Home  >  Article  >  Backend Development  >  Different configuration and operation methods of python under multiple versions and environments of Anaconda

Different configuration and operation methods of python under multiple versions and environments of Anaconda

巴扎黑
巴扎黑Original
2017-09-13 10:00:062766browse

The following editor will bring you an Anaconda multi-environment and multi-version python configuration operation method. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look

conda testing guide

Before starting this conda test, you should have downloaded and installed it Anaconda or Miniconda

Note: After installation, you should close and reopen the windows command line.

1. Conda testing process:

Use conda. First we will make sure you have installed the conda

configuration environment. Next we will demonstrate conda's environment management capabilities by creating several environments. Make it easier for you to understand everything about the environment. We'll learn how to identify which environment you are in, and how to make a copy of an environment as a backup.

Test python. We will then check which version of python can be installed, install another version of python, and switch between the two versions of python.

Check the package. We will 1) list the packages installed on our computer, 2) browse the available packages, and 3) use the conda install command to install and remove some packages. For some packages that cannot be installed using conda, we will 4) search on the Anaconda.org website. For those packages in other locations, we will 5) use the pip command to install them. We will also install a commercial package IOPro that is free for 30 days. Remove packages, environments, and conda. We will end this test by learning to remove your packages, environments, and conda.

2. Complete process Tip: At any time you can get the complete command by following the command with --help document. For example, you can learn conda’s update command with the following command.

conda update --help

1. Manage conda: Conda is both a package manager and an environment manager. You must know about package managers, which help you discover and view packages. But if we want to install a package, but this package only supports a different version of python than the one we are currently using. You only need a few lines of commands to set up an environment that can run another python version. , this is the power of the conda environment manager.

Tip: Whether you use Linux, OS X or Windows command line tools, the conda commands in your command line terminal are the same unless otherwise specified.

Check that conda has been installed.

To make sure you have installed conda in the correct location, let's check if you have successfully installed Anaconda. In your command line terminal window, enter the following code:

conda --version

Conda will return the version of the Anaconda software you installed.

Tip: If you see an error message, check whether you selected Install only for the current user during the installation process and whether you are operating under the same account. Make sure to log in with the same account and reopen the command line terminal window after installation.

Upgrade the current version of conda

Next, let us upgrade conda by using the following update command:

conda update conda

conda will compare the old and new versions and tell you which version of conda can be installed. It will also notify you of other packages being upgraded simultaneously with this upgrade.

If a new version of conda is available, it will prompt you to enter y to upgrade.

proceed ([y]/n)? y

After updating conda to the latest version , we will move on to the next topic.

2. Manage the environment. Now we demonstrate conda’s environment operations by creating some environments and then moving them around.

Create and activate an environment

Use the conda create command, followed by whatever name you wish to call it:

conda create - -name snowflake biopython

This command will create a new environment for the biopython package. The location is /envs/snowflakes

Tips: There are many commonly used command options followed by --. Can be abbreviated as a dash followed by the initial letter of the command. So the --name option has the same effect as -n. Use conda -h or conda --help to see a large number of abbreviations.

Activate this new environment

Linux, OS X: source activate snowflakes

Windows: activate snowflake`


Tips: New Development The environment will be installed by default in the envs file directory in your conda directory. You can specify a different path; see conda create -h for more information.

Tips: If we do not specify the version of python to install, donda will install the version of python we installed when we originally installed conda.

Create a second environment

This time let's create and name a new environment, and then install another version of python and the two packages Astroid and Babel.

conda create -n bunnies python=3 Astroid Babel

This will create a second new environment based on python3, containing Astroid and Babel packages, called bunnies, in the /envs/bunnies file folder.

Tips: Install the packages you want to run in this environment at the same time.

Tips: Install all the packages you want when you create the environment. Installing them one by one later may Causes dependency problems (it seems so, I don’t know how to translate this term).

Tips: You can add more conditions after the conda create command and type conda create –h to view more details.

List all environments

Now let's check the environment you have installed so far, use the conda environment info command to view it:

conda info --envs

You will see the following environment list:

conda environments:

snowflakes * /home/username/miniconda/envs/snowflakes

bunnies /home/username/miniconda/envs/bunnies

root /home/username/miniconda

Confirm the current environment

What environment are you in now? snowflakes or bunnies? To determine this, enter the following code:

conda info -envis

conda will display a list of all environments, with the current environment shown in parentheses.

(snowflakes)

Note: conda sometimes also adds an * in front of the currently active environment.

Switch to another environment (activate/deactivate)

To switch to another environment, type the following command and the name of the desired environment.

Linux, OS X: source activate snowflakes
Windows: activate snowflakes

If you want to switch from the path of your current working environment to the system root directory, type:

Linux, OS X: source deactivate
Windows: deactivate

When the environment is no longer active, it will no longer be displayed in advance.

Copy an environment

Copy an environment by cloning. Here we will create a copy called flowers by cloning snowfllakes.

conda create -n flowers --clone snowflakes

Check the environment through conda info --envs

You should now see a list of environments: flowers, bunnies, and snowflakes.

Delete an environment

If you don’t want the environment named flowers, remove the environment as follows:

conda remove -n flowers --all

To confirm that the environment named flowers has been removed, enter the following command:

conda info -e

flowers is no longer is in your environment list, so we know it was removed.

conda remove -h

3. Managing Python

Conda’s management of Python is similar to the management of other packages. So multiple installations can be easily managed and upgraded.

Check python version

First let’s check which version of python can be installed:

conda search --full --name python

You can use conda search python to see all packages with "python" in their names or add the --full --name command option to list packages that exactly match "python".

Install a different version of python

Now we assume that you need python3 to compile the program, but you don’t want to overwrite your python2.7 to upgrade, you can create And activate an environment named snakes, and install the latest version of python3 through the following command:

conda create -n snakes python=3
·Linux, OS X: source activate snakes
·Windows: activate snakes

Tips: It is wise to give the environment a vivid name, such as "Python3", but it is not interesting.

Confirm that the environment has been added successfully

In order to ensure that the snakes environment has been installed, type the following command:

conda info -e

conda will display the environment list, and the currently active environment will be enclosed in parentheses (snakes)

Check the python version in the new environment

Make sure it is running in the snakes environment is python3:

python --version

Use a different version of python

In order to use a different version of python, you can switch environments by simply Just activate it, let's see how to return to the default 2.7

·Linux, OS X: source activate snowflakes
·Windows: activate snowflakes

Check the python version:

Make sure the snowflakes environment is still running the version of python you installed when you installed conda.

python --version

Log out of the environment

When you are done with the studio in the snowflakes environment, log out of the environment and convert your Path to previous state:

·Linux, OS X: source deactivate
·Windows: deactivate

4. Management Pack

Now let’s demo the package. We have installed some packages (Astroid, Babel and some specific versions of python) when we create a new environment. We check which packages we have installed, check which ones are available, look for a specific package and install it. Next, we find and install some specified packages in the Anconda.org repository, use conda to complete more installations that pip can achieve, and install a commercial package.

View a list of packages and their versions in the environment:

Use this command to see which versions of python or other programs are installed in the environment, or Make sure certain packages have been installed or removed. In your terminal window enter:

conda list

Use the conda command to view a list of available packages

A list of packages that can be installed with conda , classified according to Python version, can be obtained from this address:

http://docs.continuum.io/anaconda/pkg-docs.html

Find a package

First let's check if the package we need can be installed via conda:

conda search beautifulsoup4

It shows the package, so we know it is available of.

Install a new package

We will install this Beautiful Soup package in the current environment, use the conda command as follows;

conda install --name bunnies beautifulsoup4

Tip: You must tell conda the name of the environment you want to install (-n bunies) otherwise it will be installed into the current environment.

Now activate the bunnies environment and use conda list to show which programs are installed.

·Linux, OS X: source activate bunnies
·Windows: activate bunnies

All platforms:

conda list

Installing a package from Anaconda.org

If a package cannot be installed using conda, we will next look for it on the Anaconda.org website. Anaconda.org provides package management services to public and private package repositories. Anaconda.org is a continuous analysis product.

Tip: You are not required to register when downloading things from Anaconda.org.

In order to download from Anaconda.org into the current environment, we need to specify Anaconda.org as a specific channel and enter the full path to the package.

In your browser, go to the http://anaconda.org website. We are looking for a package called "bottleneck", so enter "bottleneck" in the search box called "Search Anaconda Cloud" in the upper left corner and click the search button.

There are over a dozen versions of the bottleneck package available on Anaconda.org, but we want the version that is downloaded most frequently. So you can sort by download volume by clicking on the Download bar.

Click on the package name to select the most commonly downloaded package. It will link to the Anaconda.org details page to display the specific command for downloading:

conda install --channel https://conda .anaconda.ort/pandas bottleneck

Check to be downloaded Packages

conda list

Install packages via pip command

For those that cannot be installed via conda or obtained from Anaconda.org Packages, we can usually use pip (short for "pip install packages") to install packages.

Tip: pip is just a package manager, so it can't manage the environment for you. pip can't even upgrade python because it doesn't treat python as a package like conda does. But it can install some packages that conda cannot install, and vice versa (not translated here). Both pip and conda are integrated in Anaconda or miniconda.

We activate the environment where we want to place the program, and then install a program called "See" through pip.

·Linux, OS X: source activate bunnies
·Windows: activate bunnies

All platforms:

pip install see

Check pip installation

Check if See is installed:

conda list

Install commercial package

Install commercial package The process of installing other packages is abnormal. As an example, let's install and remove a newer commercial package of free trial IOPro that can speed up your python processing:

conda install iopro

Tip: Except for academic use, this version The trial period expires after 30 days

You can now install and inspect any package you want to install with conda, whether using the conda command, downloading from Anaconda.org or installing using pip, whether open source software or commercial packages.

5. Remove packages, environments, or conda

if you wish. Let's finish this testing tutorial by removing one or more test packages, environments, and conda.

Remove package

Suppose you decide not to use the commercial package IOPro anymore. You can remove it in bunnies environment.

conda remove -n bunnies iopro

Confirm that the package has been removed

Use the conda list command to confirm that IOPro has been removed

conda list

Remove environment

We no longer need the snakes environment, so enter the following command:

conda remove -n snakes --all

Confirm that the environment has been removed

To confirm that the snakes environment has been removed, enter the following command:

conda info - -envis

snakes no longer shows up in the environment list, so we know it has been removed

Removing conda

Linux, OS X:

Remove Anaconda or Miniconda installation folder

rm -rf ~/miniconda OR rm -rf ~/anaconda

Windows:

Go to the control panel and click "Add Or Remove Program", select "Python2.7 (Anaconda)" or "Python2.7 (Miniconda)" and click Remove Program.

The above is the detailed content of Different configuration and operation methods of python under multiple versions and environments of Anaconda. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn