Search code examples
tensorflowpycharmwindows-10oserror

No module named 'tensorflow.python'. Where to look for this module?


debugger:

The error occurs whenever I try to use the module in PyCharm. Installation of the module directly through cmd does not throw any exceptions. Installation of the module in PyCharm gives the following error: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'C:\Users\[USERNAME]\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\tensorflow\include\external\com_github_grpc_grpc\src\core\ext\filters\client_channel\health\health_check_client.h'

When executing a file, I get the following error: No module named 'tensorflow.python'

I have only one up-to-date 64-bit version of python installed and set to path. The name of the file executed is unique and does not coincide with any possible variables. The problem is not in IDE as Spyder has the same error as PyCharm on my PC. I have Windows 10.

I have tried reinstalling tensorflow using cmd, which doesn't actually remove tensorflow packages, so to do so I had to remove them manually, thinking that they might have been installed improperly, but it changed "no module named tensorflow" to "no module named tensorflow.python" only. Then I tried to install tensorflow.python separately, via cmd, and was told it is non-existent. I have tried updating tensorflow using cmd as I might miss some packages during the installation, this also didn't help. I have tried installing other tensorflow-related packages (keras, numpy, scikit, etc.) in hope to make up for something missing - again, nothing changed. For some reason I even created a virtual environment in my project's folder as sb here recommended. I tried to create the missing file (health_check_client.h) manually, this didn't help at all and the same error kept arising.

My tensorflow:

Name: tensorflow
Version: 2.12.0rc0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: C:\Users\Anna_Shubkina\AppData\Local\Programs\Python\Python311\Lib\site-packages
Requires: tensorflow-intel

My python: Python 3.11.2


Solution

  • This happened because of Windows limitation on long directories. I fixed this through running the following command in PowerShell as an administrator:

    New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" ` -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force