jupyternotebook中Nomodulenamedtensorflow
当我们在jupyter notebook中运⾏时可能会遇见没有某个包的情况,如下:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-24005895b065> in <module>
2 import h5py
3 import matplotlib.pyplot as plt
----> 4 import tensorflow as tf
5 from tensorflow.python.framework import ops
6 import tf_utils
ModuleNotFoundError: No module named 'tensorflow'
⾸先我的jupyter notebook是在本地设置的python3的环境deeplearning下运⾏的:
userdeMacBook-Pro:~ user$ conda activate deeplearning
(deeplearning) userdeMacBook-Pro:~ user$ jupyter notebook
但是很奇怪的是我python3的环境下已经安装好了tensorflow,但是jupyter中还是显⽰没有
(deeplearning) userdeMBP:~ user$ python
Python 3.7.2 (default, Dec 29 2018, 00:00:04)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> tensorflow.__version__
'1.13.1'
>>>
可见安装了1.13.1版本的tensorflow
tensorflow版本选择解决⽅法有:
打开你的anaconda navigator,按下图选择,之后apply安装就⾏:
报了个错:
UnsatisfiableError: The following specifications were found to be in conflic
pytorch
tensorflow == 1.11.0
use conda info <package> to check dependencies
使⽤conda info tensorflow查看依赖后,发现tensorflow <= 1.12.0版本不⽀持python3.7,⽽anaconda navigator中提供的tensorflow的最⾼版本是1.12.0,所以我就将其降到了3.6版本,即在指定的环境deeplearning下运⾏:
(deeplearning) userdeMBP:~ user$ conda install python=3.6
当然这样可能会导致⼀些之前安装的包的丢失,因为再import tensorflow时可见之前安装的tensorflow没了:
(deeplearning) userdeMBP:~ user$ python
Python 3.6.8 |Anaconda, Inc.| (default, Dec 292018, 19:04:46)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license"for more information.
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
然后再安装就可以看见安装成功:
然后再查看:
(deeplearning) userdeMBP:~ user$ python
Python 3.6.8 |Anaconda, Inc.| (default, Dec 292018, 19:04:46)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license"for more information.
>>> import tensorflow
>>> tensorflow.__version__
'1.12.0'
>>>
可见相应的环境deeplearning中成功安装了tensorflow == 1.12.0版本
⚠
如果在过程中还是有UnsatisfiableError的错,除了依赖的问题,还可以试试:userdeMBP:~ user$ conda update conda
更新conda
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论