【问题标题】:ModuleNotFoundError: No module named 'tensorflow' in anacondaModuleNotFoundError:anaconda 中没有名为“tensorflow”的模块
【发布时间】:2020-09-07 03:54:45
【问题描述】:

当我尝试导入 tensorflow 时,conda 提示出现此错误

Numpy 和所有包都导入没有错误

我在 C 语言中有 keras,但它也没有用。 我越来越多地尝试通过许多不同的方式安装 tensorflow

我该如何解决这个问题?

(base) C:\Users\ASUS>conda install -c conda-forge tensorflow
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\ASUS\Anaconda3\Anaconda

  added / updated specs:
    - tensorflow


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    absl-py-0.9.0              |   py36h9f0ad1d_1         162 KB  conda-forge
    astor-0.7.1                |             py_0          22 KB  conda-forge
    gast-0.3.3                 |             py_0          12 KB  conda-forge
    grpcio-1.23.0              |   py36hc6b9980_1         1.0 MB  conda-forge
    importlib-metadata-1.6.0   |   py36h9f0ad1d_0          42 KB  conda-forge
    keras-applications-1.0.8   |             py_1          30 KB  conda-forge
    keras-preprocessing-1.1.0  |             py_0          33 KB  conda-forge
    libprotobuf-3.11.4         |       h1a1b453_0         2.2 MB  conda-forge
    markdown-3.2.2             |             py_0          61 KB  conda-forge
    protobuf-3.11.4            |   py36h97ec31f_1         584 KB  conda-forge
    python_abi-3.6             |          1_cp36m           4 KB  conda-forge
    tensorboard-1.13.1         |           py36_0         3.3 MB  conda-forge
    tensorflow-1.13.2          |       h21ff451_0          22 KB  conda-forge
    tensorflow-base-1.13.2     |           py36_0        52.5 MB  conda-forge
    tensorflow-estimator-1.13.0|   py36h39e3cac_0         475 KB  conda-forge
    termcolor-1.1.0            |             py_2           6 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        60.5 MB

The following NEW packages will be INSTALLED:

  absl-py            conda-forge/win-64::absl-py-0.9.0-py36h9f0ad1d_1
  astor              conda-forge/noarch::astor-0.7.1-py_0
  gast               conda-forge/noarch::gast-0.3.3-py_0
  grpcio             conda-forge/win-64::grpcio-1.23.0-py36hc6b9980_1
  importlib-metadata conda-forge/win-64::importlib-metadata-1.6.0-py36h9f0ad1d_0
  keras-applications conda-forge/noarch::keras-applications-1.0.8-py_1
  keras-preprocessi~ conda-forge/noarch::keras-preprocessing-1.1.0-py_0
  libprotobuf        conda-forge/win-64::libprotobuf-3.11.4-h1a1b453_0
  markdown           conda-forge/noarch::markdown-3.2.2-py_0
  protobuf           conda-forge/win-64::protobuf-3.11.4-py36h97ec31f_1
  python_abi         conda-forge/win-64::python_abi-3.6-1_cp36m
  tensorboard        conda-forge/win-64::tensorboard-1.13.1-py36_0
  tensorflow         conda-forge/win-64::tensorflow-1.13.2-h21ff451_0
  tensorflow-base    conda-forge/win-64::tensorflow-base-1.13.2-py36_0
  tensorflow-estima~ conda-forge/win-64::tensorflow-estimator-1.13.0-py36h39e3cac_0
  termcolor          conda-forge/noarch::termcolor-1.1.0-py_2

The following packages will be UPDATED:

  ca-certificates     pkgs/main::ca-certificates-2020.1.1-0 --> conda-forge::ca-certificates-2020.4.5.1-hecc5488_0
  conda                       pkgs/main::conda-4.8.3-py36_0 --> conda-forge::conda-4.8.3-py36h9f0ad1d_1

The following packages will be SUPERSEDED by a higher-priority channel:

  certifi              pkgs/main::certifi-2020.4.5.1-py36_0 --> conda-forge::certifi-2020.4.5.1-py36h9f0ad1d_0
  openssl                                         pkgs/main --> conda-forge


Proceed ([y]/n)? y


Downloading and Extracting Packages
astor-0.7.1          | 22 KB     | ############################################################################ | 100%
markdown-3.2.2       | 61 KB     | ############################################################################ | 100%
grpcio-1.23.0        | 1.0 MB    | ############################################################################ | 100%
gast-0.3.3           | 12 KB     | ############################################################################ | 100%
termcolor-1.1.0      | 6 KB      | ############################################################################ | 100%
tensorflow-1.13.2    | 22 KB     | ############################################################################ | 100%
keras-applications-1 | 30 KB     | ############################################################################ | 100%
libprotobuf-3.11.4   | 2.2 MB    | ############################################################################ | 100%
importlib-metadata-1 | 42 KB     | ############################################################################ | 100%
keras-preprocessing- | 33 KB     | ############################################################################ | 100%
tensorboard-1.13.1   | 3.3 MB    | ############################################################################ | 100%
tensorflow-base-1.13 | 52.5 MB   | ############################################################################ | 100%
absl-py-0.9.0        | 162 KB    | ############################################################################ | 100%
python_abi-3.6       | 4 KB      | ############################################################################ | 100%
protobuf-3.11.4      | 584 KB    | ############################################################################ | 100%
tensorflow-estimator | 475 KB    | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

(base) C:\Users\ASUS>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import cv2
>>> import tensorflow
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\h5py\__init__.py:40: UserWarning: h5py is running against HDF5 1.10.5 when it was built against 1.10.4, this may cause problems
  '{0}.{1}.{2}'.format(*version.hdf5_built_version_tuple)
Warning! ***HDF5 library version mismatched error***
The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as 'LD_LIBRARY_PATH'.
You can, at your own risk, disable this warning by setting the environment
variable 'HDF5_DISABLE_VERSION_CHECK' to a value of '1'.
Setting it to 2 or higher will suppress the warning messages totally.
Headers are 1.10.4, library is 1.10.5
        SUMMARY OF THE HDF5 CONFIGURATION
        =================================

General Information:
-------------------
                   HDF5 Version: 1.10.5
                  Configured on: 2019-03-04
                  Configured by: Visual Studio 14 2015 Win64
                    Host system: Windows-10.0.17763
              Uname information: Windows
                       Byte sex: little-endian
             Installation point: C:/Program Files/HDF5

Compiling Options:
------------------
                     Build Mode:
              Debugging Symbols:
                        Asserts:
                      Profiling:
             Optimization Level:

Linking Options:
----------------
                      Libraries:
  Statically Linked Executables: OFF
                        LDFLAGS: /machine:x64
                     H5_LDFLAGS:
                     AM_LDFLAGS:
                Extra libraries:
                       Archiver:
                         Ranlib:

Languages:
----------
                              C: yes
                     C Compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe 19.0.24218.1
                       CPPFLAGS:
                    H5_CPPFLAGS:
                    AM_CPPFLAGS:
                         CFLAGS:  /DWIN32 /D_WINDOWS /W3
                      H5_CFLAGS:
                      AM_CFLAGS:
               Shared C Library: YES
               Static C Library: YES

                        Fortran: OFF
               Fortran Compiler:
                  Fortran Flags:
               H5 Fortran Flags:
               AM Fortran Flags:
         Shared Fortran Library: YES
         Static Fortran Library: YES

                            C++: ON
                   C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe 19.0.24218.1
                      C++ Flags: /DWIN32 /D_WINDOWS /W3 /GR /EHsc
                   H5 C++ Flags:
                   AM C++ Flags:
             Shared C++ Library: YES
             Static C++ Library: YES

                            JAVA: OFF
                   JAVA Compiler:

Features:
---------
                   Parallel HDF5: OFF
Parallel Filtered Dataset Writes:
              Large Parallel I/O:
              High-level library: ON
                    Threadsafety: OFF
             Default API mapping: v110
  With deprecated public symbols: ON
          I/O filters (external):  DEFLATE DECODE ENCODE
                             MPE:
                      Direct VFD:
                         dmalloc:
  Packages w/ extra debug output:
                     API Tracing: OFF
            Using memory checker: OFF
 Memory allocation sanity checks: OFF
          Function Stack Tracing: OFF
       Strict File Format Checks: OFF
    Optimization Instrumentation:
Bye...

(base) C:\Users\ASUS>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\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)])
C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\h5py\__init__.py:40: UserWarning: h5py is running against HDF5 1.10.5 when it was built against 1.10.4, this may cause problems
  '{0}.{1}.{2}'.format(*version.hdf5_built_version_tuple)
Warning! ***HDF5 library version mismatched error***
The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as 'LD_LIBRARY_PATH'.
You can, at your own risk, disable this warning by setting the environment
variable 'HDF5_DISABLE_VERSION_CHECK' to a value of '1'.
Setting it to 2 or higher will suppress the warning messages totally.
Headers are 1.10.4, library is 1.10.5
        SUMMARY OF THE HDF5 CONFIGURATION
        =================================

General Information:
-------------------
                   HDF5 Version: 1.10.5
                  Configured on: 2019-03-04
                  Configured by: Visual Studio 14 2015 Win64
                    Host system: Windows-10.0.17763
              Uname information: Windows
                       Byte sex: little-endian
             Installation point: C:/Program Files/HDF5

Compiling Options:
------------------
                     Build Mode:
              Debugging Symbols:
                        Asserts:
                      Profiling:
             Optimization Level:

Linking Options:
----------------
                      Libraries:
  Statically Linked Executables: OFF
                        LDFLAGS: /machine:x64
                     H5_LDFLAGS:
                     AM_LDFLAGS:
                Extra libraries:
                       Archiver:
                         Ranlib:

Languages:
----------
                              C: yes
                     C Compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe 19.0.24218.1
                       CPPFLAGS:
                    H5_CPPFLAGS:
                    AM_CPPFLAGS:
                         CFLAGS:  /DWIN32 /D_WINDOWS /W3
                      H5_CFLAGS:
                      AM_CFLAGS:
               Shared C Library: YES
               Static C Library: YES

                        Fortran: OFF
               Fortran Compiler:
                  Fortran Flags:
               H5 Fortran Flags:
               AM Fortran Flags:
         Shared Fortran Library: YES
         Static Fortran Library: YES

                            C++: ON
                   C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe 19.0.24218.1
                      C++ Flags: /DWIN32 /D_WINDOWS /W3 /GR /EHsc
                   H5 C++ Flags:
                   AM C++ Flags:
             Shared C++ Library: YES
             Static C++ Library: YES

                            JAVA: OFF
                   JAVA Compiler:

Features:
---------
                   Parallel HDF5: OFF
Parallel Filtered Dataset Writes:
              Large Parallel I/O:
              High-level library: ON
                    Threadsafety: OFF
             Default API mapping: v110
  With deprecated public symbols: ON
          I/O filters (external):  DEFLATE DECODE ENCODE
                             MPE:
                      Direct VFD:
                         dmalloc:
  Packages w/ extra debug output:
                     API Tracing: OFF
            Using memory checker: OFF
 Memory allocation sanity checks: OFF
          Function Stack Tracing: OFF
       Strict File Format Checks: OFF
    Optimization Instrumentation:
Bye...
(base) C:\Users\ASUS>pip install tensorflow
Requirement already satisfied: tensorflow in c:\users\asus\anaconda3\anaconda\lib\site-packages (1.13.2)
Requirement already satisfied: astor>=0.6.0 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from tensorflow) (0.8.1)
Requirement already satisfied: wheel>=0.26 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from tensorflow) (0.34.2)
Requirement already satisfied: protobuf>=3.6.1 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from tensorflow) (3.12.0)
Requirement already satisfied: gast>=0.2.0 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from tensorflow) (0.3.3)
Requirement already satisfied: numpy<2.0,>=1.16.0 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from tensorflow) (1.18.4)
WARNING: No metadata found in c:\users\asus\anaconda3\anaconda\lib\site-packages
ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'c:\\users\\asus\\anaconda3\\anaconda\\lib\\site-packages\\numpy-1.18.4.dist-info\\METADATA'
(base) C:\Users\ASUS>pip install tensorflow-gpu
Collecting tensorflow-gpu
  Downloading tensorflow_gpu-2.2.0-cp36-cp36m-win_amd64.whl (460.3 MB)
     |████████████████████████████████| 460.3 MB 811 bytes/s
Requirement already satisfied: protobuf>=3.8.0 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from tensorflow-gpu) (3.12.0)
Requirement already satisfied: absl-py>=0.7.0 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from tensorflow-gpu) (0.9.0)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/tensorflow-gpu-estimator/
Collecting tensorflow-gpu-estimator<2.3.0,>=2.2.0
  Downloading tensorflow_gpu_estimator-2.2.0-py2.py3-none-any.whl (470 kB)
     |████████████████████████████████| 470 kB 364 kB/s
Requirement already satisfied: wheel>=0.26; python_version >= "3" in c:\users\asus\anaconda3\anaconda\lib\site-packages (from tensorflow-gpu) (0.34.2)
Requirement already satisfied: numpy<2.0,>=1.16.0 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from tensorflow-gpu) (1.18.4)
WARNING: No metadata found in c:\users\asus\anaconda3\anaconda\lib\site-packages
ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'c:\\users\\asus\\anaconda3\\anaconda\\lib\\site-packages\\numpy-1.18.4.dist-info\\METADATA'

我想安装没有环境的 tensorflow 我想要它在我的 python 中

【问题讨论】:

    标签: python tensorflow anaconda


    【解决方案1】:

    虽然解决方案在 Github 中提供,但为了 stackoverflow 社区的利益,我在此处发布解决方案。

    错误:由于 EnvironmentError 无法安装软件包:[Errno 2] 没有这样的文件或?目录:'c:\users\asus\anaconda3\anaconda\lib\site-packages\numpy-1.18.4.dist -信息\元数据'

    它说c:\\users\\asus\\anaconda3\\anaconda\\lib\\site-packages\\numpy-1.18.4.dist-info\\ 上没有METADATA 文件。

    可以通过以下方法解决。

    第一种方法:创建空的METADATA 文件并将其放置在 pip 正在寻找的位置

    第二种方法: 将文件夹numpy-1.18.4.dist-info 移出并再次运行主安装。

    第三种方法: pip install tensorflow --user in the Prompt Anaconda

    更多详情请参考here

    如果没有一种方法不能解决您的问题,请告诉我们。

    【讨论】:

    • 我解决了这个错误,但我在 keras 中有另一个错误如果你能帮助检查这个错误link
    • @Mohamed Magdy,如果它回答了您的问题,请您接受并投票赞成。谢谢
    猜你喜欢
    • 2018-07-13
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 2018-01-10
    • 2018-06-01
    相关资源
    最近更新 更多