安装好anconda之后,使用下面命令创建虚拟环境:
conda create -n py3
当然也可以指定conda的初始python版本,默认的会安装pip,numpy等一下基本的包
conda create -n py3 python=3.7 -y
上述代码的说明:
pip list
命令显示的包是anconda“基环境”下面的包;使用conda list
显示该环境下面没有任何包。这个时候使用python
命令,发现python的版本往往不是我们想要的(与“基环境”的python同版本)。现在相当于有了一个空的虚拟环境了。
可以使用source activate py3
命令激活虚拟环境,在这个环境中安装的(我发现准确的说是使用conda方法安装,pip命令安装好像有点问题,可能会扰乱其他环境,待考证~)的包不会影响其他环境。
接下来,如果在安装包的时候下载很慢,或者出现下面的错误:
Error([('SSL routines', 'ssl3_get_record', 'decryption failed or bad record mac')],)
请按照下面的方法(参考:conda channel的镜像设置(设置可用清华源)),更换源。
conda config --show channels
运行结果为:
channels:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
defaults
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --set show_channel_urls yes
的作用是在安装包的时候提示包的来源,类似于下图:
接下来就可以安装自己想要的包版本了,比如先安装一个3.6版本的python(我原来的是python2.7)。
conda install python==3.6
可以使用conda命令放心安装啦
可以使用下面的命令,把虚拟环境导入到jupyter notebook中,就可以开心的写代码了~~
python -m ipykernel install --user --name deeplearn --display-name "deeplearn"
其中deeplearn是自己创建好的虚拟环境的名称,"deeplearn"是jupyter notebook里面显示出来的名称,其他的不用动。
pip install selenium -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com
搜索当前源路径下所有相关包的版本
conda search opencv
创建环境
conda create –n tensorflow-python3.6 python=3.6
删除环境
conda remove –n tensorflow-python3.6 –all
重命名环境
1 clone环境
conda create –n tf –clone tensorflow-python3.6
2 删除旧环境
conda remove –n tensorflow-python3.6 –all
查询现有环境
conda info –e
或者
conda env list
激活 环境
source active 环境名称
返回默认环境
source deactive 环境名称
导出环境
conda env export > environment.yml
用配置文件创建新的虚拟环境
conda env create –f environment.yml
切换到base环境
acticate
列出当前环境的所有包
conda list
安装requests的包
conda install requests
conda 卸载requests包
conda remove requests
更新环境
conda update requests