We will now discuss package management with Conda. In this section, we're going to take a look at the following topics:
- What is Conda?
- Managing Conda environments
- Managing Python with Conda
- Managing packages with Conda
We will now discuss package management with Conda. In this section, we're going to take a look at the following topics:
So what is Conda? Conda is the Anaconda package manager. Conda allows us to create and manage multiple environments, allowing multiple versions of Python, R, and their relevant packages to exist. This can be very useful if you need to develop for different systems with different versions of Python and their packages. Conda allows you to manage Python and R versions, and it also facilitates installation and management of packages.
A Conda environment allows developers to use and manage different versions of Python in its packages. This can be useful for testing and development on legacy systems. Environments can be saved, cloned, and exported so that others can replicate results.
Here are some common environment management commands.
For environment creation:
conda create --name env_name prog1 prog2 conda create --name env_name python=3 prog3
For listing environments:
conda env list
To verify the environment:
conda info --envs
To clone the environment:
conda create --name new_env --clone old_env
To remove environments:
conda remove --name env_name -all
Users can share environments by creating a YAML file, which recipients can use to construct an identical environment. You can do this by hand, where you effectively replicate what Anaconda would make, but it is much easier to have Anaconda create a YAML file for you.
After you have created such a file, or if you've received this file from another user, it is very easy to create a new environment.
As mentioned earlier, Anaconda allows you to manage multiple versions of Python. It is possible to search and see which versions of Python are available for installation. You can verify which version of Python is in an environment, and you can even create environments for Python 2.7. You can also update the version of Python that is in a current environment.
Let's suppose that we're interested in installing the package selenium, which is a package that is used for web scraping and also web testing. We can list the packages that are currently installed, and we can give the command to install a new package.
First, we should search to see whether the package is available from the Conda system. Not all packages that are available on pip are available from Conda. That said, it is in fact possible to install a package available from pip, although hopefully, if we wish to install a package, we can use the following command:
conda install selenium
If selenium is the package we're interested in, it can be downloaded automatically from the internet, unless you have a file that Anaconda can install directly from your system.
To install packages via pip, use the following:
pip install package_name
Packages, of course, can be removed as follows:
conda remove selenium