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)
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镜像源
pip install requests -i https://pypi.douban.com/simple