簡體   English   中英

ModuleNotFoundError:anaconda 中沒有名為“tensorflow”的模塊

[英]ModuleNotFoundError: No module named 'tensorflow' in anaconda

當我嘗試導入 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

雖然解決方案在 Github 中提供,但為了 stackoverflow 社區的利益,我在此處發布解決方案。

錯誤:由於環境錯誤而無法安裝軟件包:[Errno 2] 沒有這樣的文件或?目錄:'c:\users\asus\anaconda3\anaconda\lib\site-packages\numpy-1.18.4.dist-info\元數據'

它說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

更多詳情請參考 這里

如果沒有一種方法不能解決您的問題,請告訴我們。

嘗試使用:首先創建一個空的元數據文件,執行以下命令Conda create -n tensorflow pip python 一旦命令被執行使用:conda activate tensorflow

願你會發現這個答案很有用。 這就是命令的工作方式

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM