按照常规方案安装tensorflow出现一下问题
C:\Users\liufeng>pip install tensorflow
Collecting tensorflow
Downloading https://files.pythonhosted.org/packages/f7/08/25e47a53692c2e0dcd2211a493ddfe9007a5cd92e175d6dffa6169a0b392/tensorflow-1.14.0-cp37-cp37m-win_amd64.whl (68.3MB)
|████████████████████████████████| 68.3MB 91kB/s
......
Stored in directory: C:\Users\liufeng\AppData\Local\pip\Cache\wheels\7c\06\54\bc84598ba1daf8f970247f550b175aaaee85f68b4b0c5ab2c6
Successfully built wrapt absl-py gast termcolor
ERROR: tensorboard 1.14.0 has requirement setuptools>=41.0.0, but you'll have setuptools 40.2.0 which is incompatible.
Installing collected packages: tensorflow-estimator, keras-applications, wrapt, google-pasta, astor, absl-py, protobuf, grpcio, markdown, tensorboard, gast, termcolor, keras-preprocessing, tensorflow
Found existing installation: wrapt 1.10.11
ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
根据提示是wrapt和setuptools版本,所以重新安装这两个软件
C:\Users\liufeng>pip install --ignore-installed wrapt
Collecting wrapt
Installing collected packages: wrapt
Successfully installed wrapt-1.11.2
C:\Users\liufeng>pip install --ignore-installed setuptools
Collecting setuptools
Using cached https://files.pythonhosted.org/packages/b2/86/095d2f7829badc207c893dd4ac767e871f6cd547145df797ea26baea4e2e/setuptools-41.2.0-py2.py3-none-any.whl
ERROR: twisted 18.7.0 requires PyHamcrest>=1.9.0, which is not installed.
Installing collected packages: setuptools
Successfully installed setuptools-41.2.0
再次重新安装tensorflow,正常安装完成,但是导入模块式发现numpy版本过低出现错误
>>> import tensorflow
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
ImportError: numpy.core.multiarray failed to import
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "", line 980, in _find_and_load
SystemError: returned a result with an error set
ImportError: numpy.core._multiarray_umath failed to import
ImportError: numpy.core.umath failed to import
2019-09-19 17:19:31.549331: F tensorflow/python/lib/core/bfloat16.cc:675] Check failed: PyBfloat16_Type.tp_base != nullptr
于是删除当前numpy模块并安装最新的numpy
C:\Users\liufeng>pip uninstall numpy
Uninstalling numpy-1.15.1:
Would remove:
e:\anaconda3\lib\site-packages\numpy
e:\anaconda3\lib\site-packages\numpy-1.15.1-py3.7.egg-info
Proceed (y/n)? y
Successfully uninstalled numpy-1.15.1
C:\Users\liufeng>python -m pip install --upgrade numpy
Collecting numpy
再次导入模块时,报下面的警告
>>> import tensorflow
e:\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:516: 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)])
e:\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:517: 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)])
百度发现是numpy版本过高导致,于是挑选一个合适的numpy版本,重新安装后可以正常导入tensorflow
C:\Users\liufeng>pip install numpy==1.16.0
Collecting numpy==1.16.0
Downloading https://files.pythonhosted.org/packages/dd/3e/0d7a914ee6cceef588dd83b18e257dc474ac67028a8d340dfec644878128/numpy-1.16.0-cp37-cp37m-win_amd64.whl (11.9MB)
|████████████████████████████████| 11.9MB 3.3MB/s
Installing collected packages: numpy
Successfully installed numpy-1.16.0
C:\Users\liufeng>python
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>>