Conda use correct posture environment
Before my blog article and understand the relationship conda Python's has been the relationship between Conda and Python introduced.
This article offers some suggestions for using Conda environment.
1. Anaconda / Miniconda
I personally recommend the use of Miniconda, Miniconda contains only basic Python interpreter and Conda environment, lightweight and convenient, easy to use.
Anaconda on the basis Miniconda, Python comes with many packages and add-on tools. Anaconda in the scientific community is the popular Python solution.
Related Links:
2. Use Conda env isolation of different projects
Develop good habits, Python project must be isolated from the environment!
Whether using Python comes venv, or use Conda env, isolated environment is essential.
- Python venv create a virtual environment, we usually manually specify its creation in the corresponding project
venv/
in- Conda create an environment created will be centrally managed under the installation directory Conda
2.1 Conda Management Pack
Installation package:
conda install package_name
Uninstalling packages:
conda remove package_name
Update package:
conda update package_name
Update Conda:
conda update conda
Lists installed packages:
conda list
2.2 Conda management environment
Creating Conda environment:
conda create -n $NAME_OF_ENV python=3.6
Since Conda manage different versions of Python, is regarded as the Python package to manage , so here specify Python version, it is equivalent to specifying the package initialization Conda environment
View a list of Conda environment:
conda env list
Activate Conda environment:
conda activate $ENV_NAME
Exit the current environment:
conda deactivate
Delete Conda environment:
conda env remove -n $ENV_NAME
2.3 Practical official documents
- CONDA User guide - Tasks: Managing packages
- CONDA User guide - Tasks: Managing environments
- CONDA Cmd reference - Conda general commands
- CONDA Cmd reference - Conda vs. pip vs. virtualenv commands
3. Conda file dependencies
Export the currently active environment configuration:
conda env export > environment.yml
Using the environment.yml
created environment:
conda env create -f environment.yml
Installation pip freeze
created requirements.txt
:
conda install --yes --file requirements.txt
3.1 portability environment on Conda
In fact, in Conda environment, whether using conda env export
or pip freeze
, resulting dependency list are not easily portable .
When Conda installation package will not only install the command line specified package will install for various hardware acceleration, co-dependencies (including C ++ environment), which leads in conda environment by automatically generated dependencies can not easily portable environment .
This is both Conda advantage (to solve the problem of dependence, improve the speed), but also Conda disadvantage (due to the non-Python package depends on the platform sacrifice some portability).
Reference links:
stack overflow - How to share conda environments across platforms
4. Use recommended
4.1 Do not mix pip and conda
pip and conda resolve dependencies between packages and package installation very different way, mix the two may lead to various problems.
Suggestions : either continue to use PIP (and Venv ), or continued use Conda .
4.2 Creating development (programming) environment and use pip venv
Most (almost all) Python package characteristics are cross-platform, so when programming with Python comes venv pip and can more easily get to the desired project dependencies list.
I related blog links:
4.3 Conda deploy production (run) environment
When Conda install Python package, will be included with the installation for a variety of hardware acceleration, co-dependencies, code runs faster on and friendly. Obtained when using the development requirements.txt
to create the environment to Conda (see section III).