conda、pip环境配置

227 阅读1分钟

pip配置源

linux:
~/.pip/pip.conf

windows:
C:\Users\xxxx\pip\pip.ini

设置格式

[global]
timeout = 8
index-url =  http://mirrors.aliyun.com/pypi/simple/
extra-index-url= http://pypi.douban.com/simple/
[install]
trusted-host=
    mirrors.aliyun.com
    pypi.douban.com

说明:

a、此为设置pip的配置文件;
b、第2行是设置超时时间,单位秒;
c、第3行是指定优先下载源,第4行是备用下载源;
d、6~8行内容是配置可能需要使用https方式通信。

可用pip源

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host = mirrors.aliyun.com

pip生成requirements.txt
pip freeze > requirements.txt

pip安装requirements.txt
pip install -r requirements.txt

注意:安装requirements.txt 遇到某个包报错,可以修改requirements.txt,根据提示降低版本,或跳过

conda配置源

C:\Users\xxxx.condarc 大多数开源镜像不可用

conda常用命令:

查看安装了哪些包
conda list

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

创建python环境
conda create -n your_env_name python=x.x
conda create -n your_env_name --clone env_name

激活虚拟环境
Linux: source activate your_env_nam Windows: activate your_env_name

删除环境

conda remove -n  your_env_name --all  
conda remove --name $your_env_name $package_neme(包名)

使用以下命令生成当前环境的依赖列表
conda list --export > environment.yml

需要将environment.yml转换为requirements.txt conda env export --from-history | grep -v "prefix:" > requirements.txt

注意win10环境不支持grep, win10系统可直接导出requirements.txt,再安装requirements.txt

Windows pip install UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x90 in position 101: illegal

解决办法: 1 设置win10系统, 勾选Beta版,使用Unicode-UTF-8提供全球语言支持
参照 blog.csdn.net/qq_36287702…

2 切换其他conda