Introduction
When doing Python development, you may have come into contact with virtualenv
it, he can install different Python environment support for different environments. If you also know virtualenvwrapper
, you will find it more convenient to use, it is the right virtualenv
package, it is very convenient to create and manage multiple different development environments. For an introduction to virtualenv and virtualenvwrapper, please refer to the following:
- Virtual independent Python environment using virtualenv under Linux
- Python multi-environment management extension virtualenvwrapper
In Python, there is also a more powerful environment management tool, Conda . Conda can not only manage different development environments, but also package management like pip. The functions of Virtualenv and Conda are not very different. Personally, I think Virtualenv is used more in the field of web development, while Conda is mainly used in scientific computing environments.
Conda is an open source package management system and environment management system, which can install multiple versions and dependencies of software packages, and each environment can be easily switched. Conda supports Linux, OS X and Windows systems. Conda is primarily created for Python programs, but can package and distribute arbitrary software. There are several versions of Conda, including Anaconda, Anaconda Server and Miniconda.
Install
For the installation of Conda, please refer to the official documentation: http://conda.pydata.org/docs/installation.html , just download the installer and install it.
Take the installation under Linux miniconda
as an example. During the installation process, a miniconda directory will be created in the user's home directory by default, and ~/.bash_profile
additional configuration will be added to it. If you want to uninstall Miniconda, you only need to delete the corresponding configuration and files:
rm -rf ~/miniconda ~/.condarc ~/.conda ~/.continuum
The miniconda directory after installation is the default environment of Conda, which is named root. To activate the default environment, execute the following command:
source ~/miniconda/bin/activate root
Other environments created by the user are stored in ~/miniconda/envs
.
use
1. Create a new environment
The way to create an environment with conda is as follows:
conda create –name snowflakes ipython biopython
This will create a snowflakes
new environment called and put it ~/miniconda/envs/snowflakes
in. --name
The parameter is used to specify the environment name and can also be abbreviated as -n
. At the end of the command, you can connect the libraries and modules that need to be installed at the same time when you create them, and you can also specify the version of the library or module. For example to create a Python3 environment:
conda create -n bunnies python=3 astroid babel
It is also possible to create a new environment by cloning other environments:
conda create –name flowers –clone snowflakes
2. Activation and deactivation of the environment
To activate an environment use the following command:
source ~/miniconda2/bin/activate bunnies
On some computers it may be necessary to specify the full path, ie:
source ~/miniconda2/bin/activate bunnies
After the activation is successful, the environment name will be added before the current shell prompt, like this:
(bunnies)konghy$[~] => conda --version conda 4.0.5
To exit the current environment, use the following command:
source deactivate bunnies
3. Package installation and management
Install the package with the conda install <pkg name>
command, and you can specify the version of the package, for example:
conda install python = 3.5
If you need to install to the specified environment, use the following command:
conda install –name bunnies python=3.5
Of course, when installing conda, pip
tools are installed by default, and all dependencies can also be installed with pip.
List all packages in the current environment:
conda list
List all packages in the specified environment:
conda -n bunnies
Find installable packages:
conda search python
In this way, Conda will do fuzzy matching, that is, all packages with "python" characters will be found. If you only need to find python packages, you can use the following command:
conda search –full-name python
Updates to the package:
conda update conda python ipython
Remove packages:
conda remove –name bunnies ipython
4. Environmental Management
- View environmental information
View all environments installed in the system:
conda info –envs
View Conda environment system information:
conda info-system
View more detailed information about the environment system:
conda info - all
- Remove the environment:
Remove the package specified in the environment:
conda remove –name flowers ipython biopython
To completely remove the environment:
conda env remove –name flowers
- Export environment:
conda env export –name bunnies –file build_bunnies.yml
or
conda list -e > spec-file.txt
- Create an environment from a file:
If you are using an conda env export --name
exported file, you can create it with the following command:
conda env create -f build_bunnies.yml
If using an conda list -e
exported file, create it as follows:
conda create –name <env> –file <deps file>
- Update environment:
conda env update –name bunnies –file=environment.yml