ubuntu安装Anaconda安装及conda使用

一. 安装anaconda3详细教程
1、下载镜像
清华大学开源软件镜像站下载地址: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 下拉到最低端选择Linux,选择最新版(32/64位)下载。这里我下载的是版本Anaconda3-4.3.30-Linux-x86_64.sh
2、在Downloads文件中单击鼠标右键 ,打开终端
输入

bash Anaconda3-5.0.1-Linux-x86_64.sh 

3、安装
进入安装注册信息页面按照提示输入回车和yes。最后是否在bashrc中添加路径,选择“yes”就可以。
4、验证
运行python就可以看到已经安装好了,执行$ which python命令可以查看python路径。
在这里插入图片描述
二. conda用法

  1. conda创建虚拟环境
    使用 conda create -n your_env_name python=X.X(2.7、3.6等),anaconda 命令创建python版本为X.X、名字为your_env_name的虚拟环境。your_env_name文件可以在Anaconda安装目录envs文件下找到。 指定python版本为3.6,注意至少需要指定python版本或者要安装的包, 在不指定python版本时,自动安装最新python版本。
#创建名为your_env_name的环境
conda create -n your_env_name
#创建制定python版本的环境
conda create -n your_env_name python=3.8
#创建包含某些包(如numpy,scipy)的环境
conda create -n your_env_name numpy scipy
#创建指定python版本下包含某些包的环境
conda create -n your_env_name python=3.8 numpy scipy

这里使用conda create -n your_env_name python=3.8 创建虚拟环境时报错
“CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.continuum.i”具体解决方法见后文问题解决
2. 激活虚拟环境

source activate your_env_name
  1. 退出激活环境
source deactivate your_env_name
  1. 删除虚拟环境
conda remove -n your_env_name --all

conda remove --name your_env_name --all

  1. 在指定环境中管理包
conda list -n your_env_name
conda install --name myenv package_name 
conda remove --name myenv package_name
pip install requests
  1. 使用国内 conda 软件源加速
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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes
  1. 使用国内pip软件源加速
1.临时设置方法:
可以在使用pip的时候加在最后面加上参数 -i https://pypi.tuna.tsinghua.edu.cn/simple
例如:pip install jieba -i https://pypi.tuna.tsinghua.edu.cn/simple  # jieba 是一个包
2.永久设置方法:
pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

配置完之后就可以像平常一样安装包,速度提升几十倍
例如:pip install jieba

切换为阿里云进行下载
pip install pandas -i http://mirrors.aliyun.com/pypi/simple/   --trusted-host mirrors.aliyun.com
pip install pandas -i http://mirrors.aliyun.com/pypi/simple/

阿里云 http://mirrors.aliyun.com/pypi/simple/
豆瓣(douban) http://pypi.douban.com/simple/ 
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
  1. 导入到处环境
    (1)
    #首先通过activate target_env要分享的环境target_env,进入虚拟环境,然后输入下面的命令会在当前工作目录下生成一个environment.yml文件
conda env export > environment.yml

#小伙伴拿到environment.yml文件后,将该文件放在工作目录下,可以通过以下命令从该文件创建环境

conda env create -f environment.yaml

这时候就会生成对应名称的conda虚拟环境,如果想修改名称,可以修改yaml里面的name字段,即可

如果你想导出特定环境,可以使用-n或–name参数指定环境名称:

conda env export -n myenv > environment.yaml

导入时,可以指定新环境的名称:

conda env create -n newenv -f environment.yaml

(2) conda虚拟环境导出requirement
要在conda中导出虚拟环境的依赖列表到一个requirements.txt文件,你可以使用以下命令:

conda list -n your_env_name --export > requirements.txt
conda list -n your_env_name > requirements.txt

pip freezen > requirements.txt

不带路径的

pip list --format=freeze >requirement.txt

上面两种方案会将你这个虚拟环境所有的依赖包全部导出来,其实有的时候,我们本地有一些包,不用重新全部安装,建议使用下面的方式:

​ 首先需要安装一个库:

pip install pipreqs

然后在python项目的根目录下 使用 pipreqs ./
将your_env_name替换为你的conda虚拟环境名称。这会创建一个requirements.txt文件,其中包含了虚拟环境中所有包及其精确版本的列表。

然后使用pip安装这些依赖:

pip install -r requirements.txt

请注意,这将创建一个与conda兼容的requirements.txt文件,但是使用pip安装的包可能不会完全等同于在conda虚拟环境中原生安装的性能和功能。
三. conda常用命令

#获取版本号
conda --version 或 conda -V

#检查更新当前conda
conda update conda

#查看当前存在哪些虚拟环境
conda env list 或 conda info -e

#查看--安装--更新--删除包
conda list:
conda search package_name# 查询包
conda install package_name
conda install package_name=1.5.0
conda update package_name
conda remove package_name
pip uninstall requests

四. 问题
第一步配置conda为清华源:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
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 --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --set show_channel_urls yes
2、修改conda配置信息:

sudo gedit ~/.condarc

https://blog.csdn.net/learn_han/article/details/132852938 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/cloud/conda-forge/
  • https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/
  • https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/
  • https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  • https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/ show_channel_urls: true ssl_verify: false
    3、重点: 新开一个terminal,若有虚拟环境退出虚拟环境,再执行conda create -n robot python=3.8 (测试成功)
  • 23
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值