How to install the virtual environment under Anaconda to the specified path and install the library through the .whl file and the specified source

Generally, if we do not specify the path, the virtual environment will be installed by default in the directory where anaconda is installed. For example, mine is C:\ProgramData\Anaconda3\envs, where encvs is the root directory of the virtual environment created automatically by anaconda.

The steps for anaconda to install the virtual environment of python3.5 version are as follows:

  Enter the installation command:

  conda create -n tensorflow python=3.5


As above, after creating it, activate the virtual environment activate TensorFlow. It has a parenthesis in front of the C drive, which means that it enters the directory of the virtual environment TensorFlow. To exit the virtual environment, just type in the terminal, deactivate TensorFlow.



However, due to the small space of the C drive, what should I do if I don't want to put the virtual environment on the default C drive?

By consulting the documentation of anaconda, it is found that the specified path can be installed. 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:

  onda create --prefix=D:\python35-env\py35 python=3.5


In the above command, the path D:\python35-env is the folder created first (you can also not create it, it will be created automatically), and py35 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 includes the entire path, which is D:\python35-env\py35. The command to activate the virtual environment under the specified path is as follows:

  activate D:\python35-env\py35


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

  conda remove --prefix=D:\python35-env\py35 --all



Install python library in virtual environment

If you want to continue to install the virtual environment of python2.7, the method is the same as installing python3.6.
  After the above virtual environment py27 is installed, after activating the virtual environment, you can install other python libraries.
  For example, installing the requests library
  pip install requests
  can be installed successfully.
  If the pip installation fails, you can try the following method: (install in the specified path):
  conda install -prefix=D:\pyenv\py27 package
  Please note that the command in the default path is "conda install -n py27 package "

  Of course, there are some libraries that cannot be installed directly regardless of conda or pip, and can only be installed by downloading .whl.

       That is, Anaconda installs third-party packages (whl files)

After entering http://www.lfd.uci.edu/~gohlke/pythonlibs/ , find the corresponding Python version and system version of the whl file and download it locally, here we save it to the root directory of the D drive. Generally, py2.py3 means that both Python 2 and 3 can be installed, while cp35 means that it can only be applied to Python 3.5, and win32 and amd64 represent versions for 32-bit and 64-bit systems.
for example:
pip install D:/requests-2.18.4-py2.py3-none-any.whl



最后,来查看已安装好的虚拟环境下都安装了那些python库,输入命令:
  conda list
  发现已安装好的虚拟环境py35下只安装了少量的基本库,如果也想用3.5版来进行科学计算,需要安装许多其他的库,如果一个一个安装,则会费时费力,而且容易出错,这时anaconda提供了一个命令,可以把基于python3.5版本的anaconda中的其他库一次安装好,命令如下:
  conda install -prefix=D:\python35-env\py35 anaconda

更换pip镜像源

PyPi地址在国外,因为有墙的原因所以有些地区使用pip安装第三方库的时候会出现下载慢甚至严重的无法访问导致安装失败。通过更换pip镜像源为国内地址可以解决上述问题。这里使用豆瓣的镜像源做演示,其他的镜像源可参考 https://www.pypi-mirrors.org/ 给出的列表。
pip install requests -i https://pypi.douban.com/simple

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326752071&siteId=291194637