anaconda3安装及虚拟环境管理、pip

安装anaconda3参考:

https://blog.csdn.net/qq_15192373/article/details/81091098

安装完成后需重启终端,或者输入source ~/.bashrc

再输入python就会进入anaconda的python版本

 

anaconda使用,包管理:

https://blog.csdn.net/atpuxiner/article/details/85473485

创建虚拟环境

# 查看命令帮助
conda create --help
# 创建虚拟环境,指定名称和python版本
conda create --name venv-name python=3.6

conda create -n venv-name python=3.6.5

#列出conda已创建的环境

conda env list

# 删除一个已有的环境

conda remove --name venv-name --all

 

conda添加清华源:

1、使用如下命令

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

conda config --add https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

从channel中安装包时显示channel的url,可以进行一下设置:

conda config --set show_channel_urls yes

若不想显示,可设置为no

参考:

https://www.jianshu.com/p/21f35cb966fc

2、在home目录下.condarc文件中粘贴地址,这样就很全了

但刚开始home目录下没有.condarc文件,使用sudo gedit ~/.condarc会创建文件,1中命令也会生成这个文件

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

清华源官网Anaconda 镜像使用帮助

https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/

 

 

使用yaml文件安装指定环境

参见anaconda官网环境管理https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file

# 执行如下命令可以将当前环境下的 package 信息存入名为 environment 的 YAML 文件中。
conda env export > environment.yaml

# 同样,当执行他人的代码时,也需要配置相应的环境。这时你可以用对方分享的 YAML 文件来创建一摸一样的运行环境。

conda env create -f environment.yaml

安装时报错:prefix already exists: /home/jason/anaconda3

原因是yaml文件的首行为新安装的环境名,与已有的环境名重复,改掉。但是还是报了别的错,有个网址没识别

原因是这个网址需要翻墙,把yaml中进不去的网址删掉,留下镜像源就可以了,带jd的都删掉

使用该命令创建环境时pip安装的包会装到系统的Python目录下

#显示包安装的位置

pip show “包名”  ,例如pip show absl-py。如果安在了conda某个虚拟环境下,则在该环境下才显示

如果想安装在conda环境下面,把pip后面的包去掉,在conda环境下安装pip/pip3后再用该pip/pip3安装

#查看当前的pip所在目录:

which pip

#在conda虚拟环境下安装pip/pip3。pip可能把库安装到python2里,没有python2则两者一样,pip3安装起来比较麻烦?

#conda安装pip:

conda install pip

#anaconda安装pip3

https://blog.csdn.net/u013241595/article/details/101160741

#使用如下命令安装pip库

pip install -r cuda100_pip.txt

cuda100_pip.txt文件格式如下:

不知道在.yaml文件中加入pip的安装,然后再安装会不会可以????

 

#keras-contrib库安装不上,各种源里面都没有,找到git源码下载安装(百度查不到安装方法,在必应上搜keras-contrib install)

https://interviewbubble.com/importerror-no-module-named-keras_contrib/

pip install git+https://www.github.com/keras-team/keras-contrib.git


 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章