下载安装 Anaconda3-5.3.1-Windows-x86_64.exe

安装这个可以建立多个独立的环境,使用不同版本的 pythontensorflow,版本真的很重要,一个库版本不一样,网上的例子就跑不过。

安装过程中勾选了设置环境变量的选项,后面出问题了又自己将环境变量里的 Anaconda3 都删除了, 但应该不是环境变量的问题

开始 -> Anaconda Promopt -> 右键 ->更多 -> 以管理员运行

image.png

查看安装

conda --version

image.png

创建一个名叫 tensorflow的计算环境(名字随意)

conda create -n tensorflow python=3.7.0

激活环境,也是进入环境,每次重新进入输入

conda activate tensorflow

image.png

安装 tensorflowtensorflow-1.13.0rc1-cp37-cp37m-win_amd64.whl是下载好的安装包

pip install tensorflow-1.13.0rc1-cp37-cp37m-win_amd64.whl

查看安装包

pip list
image.png

测试代码

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print sess.run(hello)

错误

${env:DEBUGPY_LAUNCHER_PORT}='2363'; & 'd:\Anaconda3\envs\tensorflow\python.exe' 'c:\Users\crystal\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\wheels\debugpy\launcher' 'e:\AI\test\test.py'
d:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
d:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
d:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
d:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
d:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
d:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])

查找说 numpy版本过高,降低版本

pip install numpy==1.16.0

报错

image.png

设置参数

`
pip --default-timeout=100 install -U numpy==1.16.0
`
image.png

重新测试代码

import tensorflow as tf
# import os
# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

image.png

成功了,图中的警告打开注释的两行就可以了。最后是这个print函数捣鬼,到此hello world 运行成功。

切换源很重要,不然半天都下载不下来。我用的清华大学那个。
将pip源更换到国内镜像
用pip管理工具安装库文件时,默认使用国外的源文件,因此在国内的下载速度会比较慢,可能只有50KB/s。幸好,国内的一些顶级科研机构已经给我们准备好了各种镜像,下载速度可达2MB/s。
其中,比较常用的国内镜像包括:

(1)阿里云 http://mirrors.aliyun.com/pyp...
(2)豆瓣http://pypi.douban.com/simple/
(3)清华大学 https://pypi.tuna.tsinghua.ed...
(4)中国科学技术大学 http://pypi.mirrors.ustc.edu....
(5)华中科技大学http://pypi.hustunique.com/

pip --default-timeout=100 install -U tensorflow-2.1.0-cp37-cp37m-macosx_10_9_x86_64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple/

zeroyl
156 声望2 粉丝