ModuleNotFoundError: No module named 'tensorflow' in anaconda

Question:

This error came in conda prompt when I try to import tensorflow

Numpy and all packages are imported with no errors

I have keras in C but it didn’t work too.
I tried more and more to install tensorflow by many different ways

How can I solve this?

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

## Package Plan ##

  environment location: C:UsersASUSAnaconda3Anaconda

  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:UsersASUS>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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagesh5py__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:UsersASUS>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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagestensorflowpythonframeworkdtypes.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:UsersASUSAnaconda3Anacondalibsite-packagesh5py__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:UsersASUS>pip install tensorflow
Requirement already satisfied: tensorflow in c:usersasusanaconda3anacondalibsite-packages (1.13.2)
Requirement already satisfied: astor>=0.6.0 in c:usersasusanaconda3anacondalibsite-packages (from tensorflow) (0.8.1)
Requirement already satisfied: wheel>=0.26 in c:usersasusanaconda3anacondalibsite-packages (from tensorflow) (0.34.2)
Requirement already satisfied: protobuf>=3.6.1 in c:usersasusanaconda3anacondalibsite-packages (from tensorflow) (3.12.0)
Requirement already satisfied: gast>=0.2.0 in c:usersasusanaconda3anacondalibsite-packages (from tensorflow) (0.3.3)
Requirement already satisfied: numpy<2.0,>=1.16.0 in c:usersasusanaconda3anacondalibsite-packages (from tensorflow) (1.18.4)
WARNING: No metadata found in c:usersasusanaconda3anacondalibsite-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:UsersASUS>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:usersasusanaconda3anacondalibsite-packages (from tensorflow-gpu) (3.12.0)
Requirement already satisfied: absl-py>=0.7.0 in c:usersasusanaconda3anacondalibsite-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:usersasusanaconda3anacondalibsite-packages (from tensorflow-gpu) (0.34.2)
Requirement already satisfied: numpy<2.0,>=1.16.0 in c:usersasusanaconda3anacondalibsite-packages (from tensorflow-gpu) (1.18.4)
WARNING: No metadata found in c:usersasusanaconda3anacondalibsite-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'

I want to install tensorflow without envs
I want it in my python

Asked By: Mohamed Magdy

||

Answers:

Though the solution is presented in Github, for the benefit of stackoverflow community i am posting solution here.

ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or ?directory: ‘c:usersasusanaconda3anacondalibsite-packagesnumpy-1.18.4.dist-infoMETADATA’

It say’s there is no METADATA file present at c:\users\asus\anaconda3\anaconda\lib\site-packages\numpy-1.18.4.dist-info\.

It can be solved using below methods.

First Method: Create empty METADATA file and place it in the location pip was looking

Second Method: Moved the folder numpy-1.18.4.dist-info out and ran the main installation again.

Third Method: pip install tensorflow –user in the Prompt Anaconda

For more details please refer here.

If none of methods doesn’t resolve your problem, please let us know.

Answered By: Tensorflow Warrior

try using:
first create an empty metadata file,execute following command
Conda create -n tensorflow pip python
once command been executed use:
conda activate tensorflow

May you’ll find this answer usefull.This is how the command works

Answered By: Nandita
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.