0、建议从官方网站下载anaconda,不要走清华源等第三方,否则无法自动更新。
https://www.anaconda.com/download
1、清除Anaconda和pip的pkt:
可以通过命令行删除,
Google讨论组里推荐用conda clean -p删除未使用的的包;实际conda clean -a更强力些。
对于pip,pip cache purge
1.1干净卸载的方法:
安装 Anaconda-Clean package
打开Anaconda Prompt,输入命令行:

conda install anaconda-clean

接着输入命令行进行卸载:

anaconda-clean --yes

1.2 anaconda 安装用户自己提供的包(比如该目录下有名为pytorch.tar.bz2的包)

conda install --use-local pytorch.tar.bz2

2、pycharm自动执行requirement.txt:
Settings/Preferences -> Tools | Python Integrated Tools.
选项 Package requirements file field 中填入 requirements.txt。

3、pip 多个源
1.首先我们需要一个pip.ini文件,于是我们在自己的用户目录下创建文件夹pip在里面创建文件pip.ini文件
2.在里面编辑 C:\Users\Liu\pip\pip.ini

[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple/
extra-index-url = https://pypi.mirrors.ustc.edu.cn/simple/
        https://mirrors.aliyun.com/pypi/simple/
        https://pypi.tuna.tsinghua.edu.cn/simple/
        http://pypi.mirrors.ustc.edu.cn/simple/
        https://pypi.org/simple/
trusted-host = pypi.mirrors.ustc.edu.cn
        pypi.mirrors.ustc.edu.cn
        mirrors.aliyun.com
        pypi.tuna.tsinghua.edu.cn
        pypi.mirrors.ustc.edu.cn
        pypi.org

4、pip conda的requirement的生成:

python3 -m pip freeze > requirements2.txt
conda list -e > requirements3.txt

5、requirement文件的读取:

python3 -m pip install -r requirements.txt
conda install --yes --file requirements.txt

6、直接迁移Anaconda环境到新机器(Anaconda迁移到/media/ExtHDD2/lqh/anaconda3
在用户环境变量/home/liu/.bashrc文件末尾添加,添加完成后使用source .bashrc使其生效

# add cuda
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export PATH=$PATH:/usr/local/cuda/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda
CUDAVER=cuda
export PATH=/usr/local/$CUDAVER/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/$CUDAVER/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/$CUDAVER/lib64:$LD_LIBRARY_PATH
export CUDA_PATH=/usr/local/$CUDAVER
export CUDA_ROOT=/usr/local/$CUDAVER
export CUDA_HOME=/usr/local/$CUDAVER
# 注意 上文是cuda的,与anaconda无关。我保留上面是为了自己日后方便!!

# added by Anaconda3 installer
#export PATH="/home/ubuntu/yes/bin:$PATH" #这个会影响pycharm的terminal与解释器设置的python是否一致
#还会影响你的pip命令安装包的位置,相当于Windows的用户Path环境变量
export PATH="/media/ExtHDD2/lqh/anaconda3/bin:$PATH"

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/media/ExtHDD2/lqh/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/media/ExtHDD2/lqh/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/media/ExtHDD2/lqh/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/media/ExtHDD2/lqh/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

7、直接修改pip全局源,不用修改配置文件:

pip config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple

8、anaconda使用国内源: 参考:https://blog.csdn.net/qq_47403533/article/details/116886693
通过conda config命令生成配置文件这里,我们使用清华的镜像:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
第一步、在CMD命令行输入以下两条命令:

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

第二步、打开目录C:\Users<你的用户名>下就会生成配置文件.condarc。
第三步、修改配置文件,删除上述配置文件.condarc中的-defaults,然后保存,最终版本文件如下:

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/linux-64/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/noarch/
  #- defaults
show_channel_urls: true

第四步、查看是否生效,通过命令conda info查看当前配置信息,内容如下,即修改成功,关注 channel URLs字段内容。

conda info active environment : base
active env location : C:\Users\27342\Anaconda3 shell level : 1      
user config file : C:\Users\27342\.condarcpopulated 
config files : C:\Users\27342\.condarc conda version : 4.5.11   
conda-build version : 3.15.1 python version : 3.7.0.final.0 
base environment : C:\Users\27342\Anaconda3 (writable) 
channel URLs : https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64 
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch package cache : 
C:\Users\27342\Anaconda3\pkgs 
C:\Users\27342\AppData\Local\conda\conda\pkgs envs directories : 
C:\Users\27342\Anaconda3\envs C:\Users\27342\AppData\Local\conda\conda\envs 
C:\Users\27342\.conda\envs platform : win-64 user-agent : conda/4.5.11 requests/2.19.1 C
Python/3.7.0 Windows/10 Windows/10.0.18362 
administrator : False netrc file : None offline mode : False

第五步、测试一下,运行。

conda clean -i

清除索引缓存,保证用的是镜像站提供的索引。
8、conda添加默认环境目录:

conda config --add envs_dirs D:\Anaconda\envs

9、conda使用他人脚本创建venv文件夹类型的环境:
如SD-diffusion webui.sh。
当前激活的环境版本就是bash 创建venv的环境版本。
10、有时候显示没有特定版本python的特定包,是因为pip/conda的源有问题。换几个。
11、anaconda更新命令(体现在conda -V),这东西玄学,三个命令都试试(不建议使用任何第三方源)

conda update conda
conda update -n base conda
conda update --all

最后修改:2024 年 06 月 04 日
如果觉得我的文章对你有用,请随意赞赏