zhuanlan.zhihu.com/p/32925500
[toc]
Requirement.txt
pip freeze > requirements.txt
pip install -r requirements.txt
Anaconda
安装、换源
换ubuntu的apt-get源
https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
在清华源下载anaconda并安装
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
conda换清华源
https://mirror.tuna.tsinghua.edu.cn/help/anaconda/(直接修改~/.condarc,优先使用)
或者
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 --show-sources
设置延迟(等待时间)
conda config --set remote_read_timeout_secs 600.0
本地安装
conda install --offline ./cudnn-7.0.5-cuda8.0_0.tar.bz2
使用虚拟环境后,最好用下面的命令来安装依赖包
python -m pip install xxx
conda命令
创建环境
conda create --name <env_name> <package_name1> <package_name2> ……
复制环境
conda create --name <new_env_name> --clone <copied_env_name>
显示已创建环境
conda env list
conda info -e
删除环境
conda remove --name <env_name> --all
激活/退出
source activate <env_name>
source deactivate
获取当前环境中已安装包的信息
conda list
安装包
conda install -name <env_name> <package_name>
删除包
conda remove -name <env_name> <package_name>
更新包
conda update --all
conda upgrade --all
取消自动激活base
conda config --set auto_activate_base false
生成、使用requirement.txt
conda list -e > requirements.txt
conda install --yes --file requirements.txt
新建python3.6和tensorflow-gpu1.12.0环境
conda create -n py3.6 python=3.6 tensorflow-gpu=1.12
Virtualenv
virtualenv的安装和基本使用
创建虚拟环境
python -m venv 【包名】
或者
pip install virtualenv
virtualenv env(directory path)
激活环境
source env/bin/activate
deactivate
python3 -m pip install whatever
存在多Python版本时pip的用法
brew unlink python 解除绑定
安装python3.6.5_1:
brew install —ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb
切换python版本:
brew switch python 3.7.3
brew switch python 3.6.5_1
定位命令位置
which
type
locate
whereis
ls -al