anaconda

mac2025-07-09  3

卸载: 直接删除 ~/下载/ENTER/   (anaconda3 和.conda), 然后清除 ~/.bashrc 中conda相关的字段

 

安装: sudo ./Anaconda3-5.2.0-Linux-x86_64.sh -u   -u表示覆盖安装 []中是默认值,询问过程要求按ENTER的直接回车... 不需要 init到shell

安装完成配置 ~/.bashrc: export PATH="/home/gld/anaconda3/bin:$PATH" sudo chown 1000:1000 /home/fang/.conda/     &&  sudo chmod 777 /home/fang/.conda/

conda --version conda init bash  初始化bash,这样conda会在~/.bashrc下添加init,conda base环境会接管shell(主要是接管python的包, pip install 安装的东西都会在conda的 沙箱/虚拟环境 中) conda upgrade --all  升级所有工具包

查看conda基本信息: conda info

########################################################################

查看已经有的环境: conda env list     #等价于 conda info -e    

创建一个环境: conda create -n fang python=3  创建一个名为fang的虚拟环境,python版本为python3最新版 conda env remove -n fang   删除一个环境

激活一个环境 conda activate fang #或者 source avtivate fang,一样的. windows 上则直接 activate fang conda deactivate

导出当前环境 conda env export > environment.yaml 创建并加载一个环境 conda env create -f environment.yaml

######################################################################## 安装一个包 conda install requests  # 或者 pip install requests

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch 卸载一个包 conda remove requests  # 或者 pip uninstall requests

(卸载一个包之后需要 conda clean --all 才会将缓存在anaconda3/pkgs/下的包删除? conda clean -t 删除conda保存的tar包,conda clean -p 删除所有没被any env用到的包)

搜索一个包 conda search beautifulsoup #会列出这个包的所有可用版本

查看当前环境中的包信息 conda list   貌似 pip freeze 可以导出一个 pip requirements.txt 文件

########################################################################

添加国内源:

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 --remove-key channels

在执行conda config 命令的时候

会在当前用户目录下创建 .condarc  文件,可以查看更换源前后该文件内容的变化。

 

 

########################################################################

当直接安装时:

conda install pytorch=1.4  torchvision cudatoolkit=10.0 cudnn=7 -y

输出:

    The following packages will be SUPERSEDED by a higher-priority channel:             pytorch            anaconda/pkgs/main::pytorch-1.5.0-cpu~ --> anaconda/cloud//pytorch::pytorch-1.4.0-py3.7_cuda10.0.130_cudnn7.6.3_0                       Downloading and Extracting Packages     pytorch-1.4.0        | 422.7 MB  | ####################################################3                                                                                                                                                           |  25%           CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud//pytorch/linux-64/pytorch-1.4.0-py3.7_cuda10.0.130_cudnn7.6.3_0.tar.bz2>     Elapsed: -           An HTTP error occurred when trying to retrieve this URL.     HTTP errors are often intermittent, and a simple retry will get you on your way.

可以看出是网络故障导致下载安装失败。此时可以 wget -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud//pytorch/linux-64/pytorch-1.4.0-py3.7_cuda10.0.130_cudnn7.6.3_0.tar.bz2 将其下载到本地,然后使用

conda install --use-local pytorch-1.4.0-py3.7_cuda10.0.130_cudnn7.6.3_0.tar.bz2

参考

https://blog.csdn.net/guolindonggld/article/details/82595473 https://www.jianshu.com/p/eaee1fadc1e9

https://blog.csdn.net/xiaosongshine/article/details/108511743

最新回复(0)