TensorFlow低版本安装

更新pip
pip install --upgrade pip

查看已有的环境

conda env list

激活环境与取消环境
To activate this environment, use

     $ conda activate tensorflow

To deactivate an active environment, use

     $ conda deactivate

3、删除环境
conda remove --name <env_name> --all

下面是创建env环境激活,并且搭建低版本tensorflow的步骤。

1.在命令行中使用以下命令创建 conda 环境(如果使用 Windows,最好在命令行中以管理员身份执行):

python35 是环境名称,这样做与原来环境不冲突,也可以直接在原来环境安装,看自己情况

 conda create -n python35 python=3.5
  
  # To activate this environment, use
#
#     $ conda activate python35
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(base) PS C:\Users\Administrator> conda activate python35

4.根据要在 conda 环境中安装的 TensorFlow 版本1.3.0或者1.8.0,输入以下命令:
pip install tensorflow==1.8.0

或者
先把依赖包安装了(这些依赖包有些tensorflow 1.8 不会自动去下载安装,但是会以红字提示,为了一次性安装好无问题,最好先把依赖包先安装了):

python -m pip install html5lib bleach ipykernel
 python -m pip install --ignore-installed --upgrade pip setuptools

我安装完也没出错,有一些waring,问题不大。
然后就是安装TensorFlow了,我稍微修改了一下,参考了其他资源,这里要加版本号,不加可能就是最新的版本了。

python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==1.8

安装结束。后面还有个小问题,继续往下看嗷

  1. 测试TensorFlow
    这里测试一下是否有问题。
    还是在TensorFlow环境下,编写个简单的python。首先切换到python下。可以使用python,或者ipython输入。
(tensorflow) C:\Users\de'l'l>python

运行过程:

(tensorflow) C:\Users\de'l'l>python
Python 3.6.10 |Anaconda, Inc.| (default, May  7 2020, 19:46:08) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

下面导入TensorFlow出问题了

>>> import tensorflow as tf

运行过程:

>>> import tensorflow as tf
D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:519: 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:520: 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:521: 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:522: 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:523: 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: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_resource = np.dtype([("resource", np.ubyte, 1)])

这里参考了1.ubuntu安装anaconda和tensorflow
2.anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes
解决方法如下:
找到D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py,这里的前缀是你的anaconda安装地址,运行结果里也会显示。出错的行数也可能不同,具体看你的运行过程了。我测试后发现需要将报错的几个都修改一下,就不会再出现了。
将我的520行的_np_quint8 = np.dtype([(“quint8”, np.uint8, 1)])改为

_np_quint8 = np.dtype([("quint8", np.uint8, (1,))])

其他的也是类似的,改成(1,)

原版:

_np_qint8 = np.dtype([("qint8", np.int8, 1)])
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
_np_qint32 = np.dtype([("qint32", np.int32, 1)])

修改后

_np_qint8 = np.dtype([("qint8", np.int8, (1,))])
_np_quint8 = np.dtype([("quint8", np.uint8, (1,))])
_np_qint16 = np.dtype([("qint16", np.int16, (1,))])
_np_quint16 = np.dtype([("quint16", np.uint16, (1,))])
_np_qint32 = np.dtype([("qint32", np.int32, (1,))])

后面还有一句:

#np_resource = np.dtype([("resource", np.ubyte, 1)])
np_resource = np.dtype([("resource", np.ubyte, (1,))])

记得保存,再次运行

import tensorflow as tf
   c=tf.constant("helloworld")
   s=tf.Session()
   s.run(c)

中间出现了

1
2020-06-11 : I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

好像是说我的cpu不太行,问题不大。
最后结果

>>> s.run(c)
b'helloworld'

安装TensorFlow成功了。

到这一步已经安装好了tensorflow低版本

如果要在Jupyter使用,需要以下步骤

  1. 在jupyter notebook上运行

当我们用Anaconda自带的iPython和Spyder以及jupyter notebook中输入import tensorflow as tf的时候会失败,显示如下No module named 'tensorflow‘,原因是我们没有在TensorFlow的环境下打开它们。
需要在TensorFlow环境下安装插件,就以jupyter notebook为例。

打开Anaconda Navigator—>Environments—>tensorflow,选择Not installed,找到iPython和Spyder以及jupyter并安装,点击下面的apply。
在这里插入图片描述
安装好后,可以通过命令行activate tensorflow来启动tensorflow,也可以直接去菜单找到下面框选的,选用就行了
在这里插入图片描述

jupyter中可以运行

在这里插入图片描述

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值