conda -V
下载pip:默认安装的是pip 9.0.1版本,我们后续需要pip config来切换镜像源地址,我们需要升级pip版本
升级pip:python -m pip install D:\downloads\chrom_download\pip-20.3b1-py2.py3-none-any.whl
打开anaconda删除默认的channels:
http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
,这里的https可能会报错,所以使用httpconda config --remove-key channels
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes# pip配置国内源
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
conda create -n tensorflow python=3.6
conda info --envs
,可以发现,除了基础环境base外,我们还可以看到刚刚创建的名为tensorflow的环境activate tensorflow
conda deactivate
#指定版本(建议安装所需版本)
pip install tensorflow-cpu==1.2.1
# 卸载
pip uninstall tensorflow-cpu
pip uninstall keraspip install tensorflow-cpu==1.2.1
python
切换到tensorflow环境的python下import tensorflow as tf
tf.__version__
,如果正常返回版本号,没有报错证明TensorFlow安装成功opencv安装:pip install opencv-python==3.3.1.11
安装opencv-contrib:pip install opencv-contrib-python==3.3.0.10
(如果提示权限不足,关闭后使用管理员打开Anaconda Prompt)
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
:这个可以加快pycharm中tensorflow的运行以及降低警告级别import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'hello = tf.constant("hello world")
with tf.Session() as sess:print(sess.run(hello))
上面在代码中添加了警告级别的设置:这个也可以通过直接设置环境变量一劳永逸
opencv环境验证:任意找一张图片,放到项目目录下,运行如下代码能够显示代表opencv环境搭建成功
import cv2img = cv2.imread('image0.jpg', 1)
cv2.imshow('image', img)cv2.waitKey(0)
打开anaconda3的Home:选择tensorflow环境,点击jupyter notebook下的install
jupyter也可以从命令行启动:
其他备注:如果打开Anaconda3卡在初始化,可以尝试使用管理员运行