1 更换 conda 的源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes
2 更换 pip 源
创建配置文件:
mkdir ~/.pip
vim ~/.pip/pip.conf
添加内容:
[global]
timeout = 6000
index-url = https://pypi.mirrors.ustc.edu.cn/simple/
trusted-host = pypi.tuna.tsinghua.edu.cn
其中,地址可以更换为这些:
- 阿里云 http://mirrors.aliyun.com/pypi/simple/
- 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
- 豆瓣 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/
3 创建环境
conda create -n new python=3.7 //这里的环境名称为new
4 激活环境:
source activate new
5 删除环境
conda remove -n rcnn --all
6 安装各种模块
6.1 opencv 模块
conda install opencv
pip3 install opencv-contrib-python
6.2 其它模块
pip install numpy
pip install matplotlib
pip install Pillow //PIL相关
pip install pandas //提供了dataframe等方便处理表格数据的数据结构
pip install jieba //中文分词组件
pip install -U scikit-learn //基于scipy和numpy的开源机器学习模块,有各种算法
pip install theano //是一个机器学习库
pip install nose
pip install parameterized
//pip install --upgrade --ignore-installed tensorflow //安装cpu版本的TensorFlow
等等...
7 安装tensorflow-gpu(windos)
小米笔记本(显卡mx150)见说明
python | CUDA | cudnn | tensorflow-gpu |
---|---|---|---|
3.6 | 10.0.130 | 7.6.0 | 12.0.0 |
1) 安装CUDA、cudnn
2) 在conda上创建虚拟环境,并进入虚拟环境
3) 用下面命令安装tensorflow-cpu-1.12.0版本
pip install tensorflow==1.12.0
4) 等待上一步下载时,可以从这里下载tensorflow-gpu-1.12.0的轮子,用来支持cuda10的,当上一步安装完成后,再执行命令:
pip install 路径\tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl
5) 上一步完成则表明tensorflow-gpu-1.12.0安装完成
6) 测试代码:
import tensorflow as tf
with tf.device('/cpu:0'):
a = tf.constant([1.0,2.0,3.0],shape=[3],name='a')
b = tf.constant([1.0,2.0,3.0],shape=[3],name='b')
with tf.device('/gpu:1'):
c = a+b
#注意:allow_soft_placement=True表明:计算设备可自行选择,如果没有这个参数,会报错。
#因为不是所有的操作都可以被放在GPU上,如果强行将无法放在GPU上的操作指定到GPU上,将会报错。
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=True))
#sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
sess.run(tf.global_variables_initializer())
print(sess.run(c))
结果:
[2. 4. 6.]