Python:anaconda Installing a virtual environment to a specified path

Source: Internet
Author: User
Tags virtual environment

1 past Troubles

For some time, you want to use a different Python version of the Anaconda, directly from the official website downloaded two different anaconda version to install.
At first, I didn't think it was a problem. A short period of time, when installing other third-party libraries, often found that the installation failed, and often the following problems:

This question, I Google, Baidu and so on for a long time, also did not solve well. Later, I uninstalled the two versions of Anaconda, reinstalled one of the versions, and found that there were no more third-party libraries to install.
It is possible that the above problem is caused by the simultaneous installation of two versions of Anaconda (though I am not entirely sure of that).

2 Installing the Virtual environment

Although only one version of Anaconda is installed, it works well, but sometimes it needs to run anaconda based on different Python versions. Later I learned that Anaconda can run different versions of Python in a virtual environment.
The following steps demonstrate my installation process, and I hope you can avoid some pits.
First of all, my installation environment:

  • Windows7,64 bit System
  • The anaconda4.2.0 version is currently installed (based on python3.5)
    Since it is often seen that the python3.6 version runs more efficiently than the 3.5 version, there is an impulse to install 3.6, but since some Python libraries do not support 3.6, the main version is still dominated by 3.5.
    Anaconda the steps to install the python3.6 version of the virtual environment are as follows:
    Enter the installation command:
    conda create -n py36 python=3.6
    The results are as follows:

    The "-N" command installs the virtual environment under the default Envs directory for the Anaconda installed path.
    As you can see, there is a warning in the command line that the hint may cause some problems because there are spaces in my Anaconda default installation path. As a result of this warning, I did not continue to install down.
    In addition, my path in the C-drive, considering that there may not be much space, or do not continue to the C-disk loaded things. So, if you can install in the other specified path and there are no spaces in the path, do not solve the problem.
    By reviewing the Anaconda documentation, it is possible to install the specified path. You can enter the following command to view:
    conda create --help
    the command to install the virtual environment to the specified path is as follows:
    conda create --prefix=D:\python36\py36 python=3.6

    In the above command, path D:\python36 is the first-built folder, and Py36 is the name of the virtual environment that needs to be installed. Note that after the installation is complete, the full name of the virtual environment contains the entire path, which is D:\python36\py36. The command to activate the virtual environment under the specified path is as follows:
    activate D:\python36\py36
    The commands to exit the virtual environment are as follows:
    deactivate

To delete a virtual environment under a specified path, use the following command:

conda remove --prefix=D:\python36\py36 --all


Interrupted by a hard wide: technical articles forwarded too much. The article comes from the public "Python Data Path" (id:pydataroad).

3 Installing the Python library in a virtual environment

If you also want to continue installing python2.7 virtual environments, the method is consistent with the installation of python3.6.
After the installation of the above virtual environment Py27 is complete, additional Python libraries can be installed after the virtual environment has been activated.
such as installing the requests library

pip install requests

can be installed successfully.
If you encounter pip Ann as a failure , try the following: (install under the specified path):

conda install -prefix=D:\pyenv\py27 package

Note that the command under the default path is "Conda install-n py27 Package"
Of course, there are some libraries that cannot be installed directly, either Conda or Pip, and can only be downloaded. WHL .
The installation method can refer to the following article:

    • Anaconda installing third-party packages (WHL files)

Finally, to see which Python libraries are installed in the installed virtual environment, enter the command:

conda list

Discover installed virtual Environments py36 only a small number of base libraries are installed. If you also want to use version 3.6 for scientific calculations, you need to install a number of other libraries, if one installation, it will be time-consuming and error-prone, then Anaconda provides a command can be based on the python3.6 version of the Anaconda other libraries installed at once, the command is as follows:

conda install -prefix=D:\pyenv\py36 anaconda


Please pay special attention to all installation, installation package will be many, installation time is longer, while occupying the installation space will be relatively large, please choose whether to install according to your own needs
I've spent about 1 hours installing all of py36 's libraries.

Expand reading:

    1. Anaconda installing third-party packages (WHL files)

    2. Python: An article mastering the basic usage of numpy

    3. Python job search Top10 City to see if there is a city of your own

?

Python:anaconda Installing a virtual environment to a specified path

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.