Skip to content

Instantly share code, notes, and snippets.

@zhaojiafu
Last active August 30, 2021 12:20
Show Gist options
  • Save zhaojiafu/5398f8af394914580310b62c13339d52 to your computer and use it in GitHub Desktop.
Save zhaojiafu/5398f8af394914580310b62c13339d52 to your computer and use it in GitHub Desktop.
[conda和pip的常用命令] conda和pip常用命令 #conda #pip #镜像源

项目依赖模块:

pip install pipreqs pipreqs ./ --encoding utf-8

1、镜像源:

阿里云 http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

豆瓣(douban) http://pypi.douban.com/simple/

清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

百度源: https://mirror.baidu.com/pypi/simple
阿里云 速度最快 http://mirrors.aliyun.com/pypi/simple/ 
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
Python官方 https://pypi.python.org/simple/
v2ex http://pypi.v2ex.com/simple/
中国科学院 http://pypi.mirrors.opencas.cn/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

华为源:
https://mirrors.huaweicloud.com/repository/pypi/simple
# 登录之后的:
https://repo.huaweicloud.com/repository/pypi/simple

2、pip一些常用命令:

mkvirtualenv [name]:创建运行环境
workon [name]: 工作在 [name] 环境 或 从其它环境切换到 [name] 环境
deactivate: 退出终端环境
rmvirtualenv ENV:删除运行环境ENV
lsvirtualenv: 列出所有的虚拟环境
cdvirtualenv:进入到虚拟环境所在的目录lssitepackages: 列出当前环境安装了的包

3、永久設置pip的国内源

pip config set global.trusted-host mirrors.aliyun.com
pip config set global.index-url https://mirrors.aliyun.com/simple

pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/

pip config set global.trusted-host repo.huaweicloud.com
pip config set global.index-url https://repo.huaweicloud.com/repository/pypi/simple


pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install  -i https://pypi.tuna.tsinghua.edu.cn/simple/  --upgrade

3、conda一些常用命令:

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/bioconda/ conda config --set show_channel_urls yes

如果报错: 执行: conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64 conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64 conda config --set show_channel_urls yes

打开用户目录下的 “.condarc” 文件 如果channels 下面有 “- default” 的话需要删除它

执行“conda config --remove-key channels”命令,恢复Anaconda的源为默认。再配置镜像源试试

批量升级模块 conda update --all 检测是否版本过期 conda search --outdated

升级conda也会升级模块版本。

conda update conda conda update --force conda

conda创建使用虚拟环境

https://blog.csdn.net/weixin_43590290/article/details/109237037 查看所有conda环境:conda env list 新建conda环境(env_name就是创建的环境名,可以自定义): conda create -n env_name conda create -n xxx python=3.8 #xxx为你要创建的虚拟环境名称 删除一个环境: conda remove -n rcnn --all 激活conda环境:conda activate env_name 退出当前conda环境(返回base环境):conda deactivate 安装和卸载python包:conda install numpy # conda uninstall numpy 查看已安装python包列表:conda list -n env_name

conda activate tf_demo1 conda activate tf_demo2

4、tensorflow的安装:

import tensorflow as tf

print(tf.version) # TensorFlow版本信息

print(tf.test.is_gpu_available()) # TensorFlow GPU支持

exit() #退出python命令行

tensorflow中使用GPU的设置方法 https://blog.csdn.net/weixin_41012399/article/details/94573591

使用tensorflow2.x训练的时候关于GPU的设置 https://blog.csdn.net/weixin_43213607/article/details/108576900

5、3070显卡安装1.14版本的tensorflow:

可以的,需要按照这种方法来装,通过conda安装cudatoolkit=10.0,cudnn=7。指令如下:

conda install cudatoolkit=10.0 cudnn=7 pip install tensorflow-gpu==1.14

conda install cudatoolkit=11.2 cudnn=8

6、3070显卡安装pytorch

参考torch官网:
https://pytorch.org/get-started/previous-versions/

# 默认已经安装pytorch1.7
conda install torchvision==0.8.2 torchaudio==0.7.2
# 如果没有安装pytorch
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch

# CUDA 11.0
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment