Trouble importing libraries site-packages

I have trouble importing libraries such as tensorflow, keras, gymnasium…
My sys.path putputs

[‘’, ‘C:\Python\Demcon2021\python39.zip’, ‘C:\Python\Demcon2021\DLLs’, ‘C:\Python\Demcon2021\lib’, ‘C:\Python\Demcon2021’, ‘C:\Python\Demcon2021\lib\site-packages’, ‘C:\Python\Demcon2021\lib\site-packages\win32’, ‘C:\Python\Demcon2021\lib\site-packages\win32\lib’, ‘C:\Python\Demcon2021\lib\site-packages\Pythonwin’]

The libraries i want to import are in folder: C:\Python\Demcon2021\Lib\site-packages

When I try to:
import numpy
import tensorflow
import keras
import gymnasium

I get an error for all starting from tensorflow. The strange thing to me is that there is no numpy import problem, they are all in the same directory.

I get the following error:

Traceback (most recent call last):

  • Cell In[3], line 1*
  • import tensorflow*

ModuleNotFoundError: No module named ‘tensorflow’

If I run the commands :
import sys
sys.path.append(“C:\Python\Demcon2021\Lib\site-packages”)

it works. but it seems wrong to run these lines before i do any kind of python project.
How can I fix this problem?

Thank you already

lib is not equal to Lib

Probably there is a Numpy somewhere else in your site-packages in your sys.path?

1 Like

I was suspecting that, i thought maybe it was a font issue. when i check for “/lib” nothing exists.
How can i permanently add ‘/Lib/site-packages’ tot eh PATH

actually when i copy paste “C:\Python\Demcon2021\lib\site-packages” in file explorer it redirects me to “/Lib/site-packages”

All your other folders in the path are subdirectories of lib, not Lib. “How did the libraries land in C:\Python\Demcon2021\Lib\site-packages?” is a question you should first answer. Otherwise you may land into trouble for libraries that are in the subdirectory of lib.

1 Like

I changed the folder name LIB to lib and realised in the ide i was using, Spyder, i had a different python interpreter than the one i downloaded. So i changed the python interpreter to the one with tensorflow, keras… and now it works problem free.
I realised it when you mentioned there can be another numpy.

Thank you

To summarise for someone else that may have the same problem. I was getting the error message i explained above in the beginning. I thought problem was not having the correct directory on the python PATH. I realised in the IDE i was using the python interpreter was set to the one that came with the IDE.

I checked this suing the lines:
import sys
print(sys.path)

You should be able to see where the python interpreter is.

I changed the python interpreter to the one where i was downloading the libraries for. I changed from the defult IDE interpreter to the python i installed from online.

That solved the problem. So the python interpreter was not the one where i was downloading the libraries for.

Windows file system is not case-sensitive that should not matter right?

1 Like

Is that still the case? It has been ages since I developed on Windows.

If that is so, I was worrying for nothing.

then me changing the Lib to lib made no difference but changing tot he correct python interpreter made the difference.

Yes it still true. I think there are options to run case sensitive file systems on Windows, but I would be surprised to see a home user with such a setup as its a rare power user idea.

To be case sensitive will likely break lots of Windows software.

Lib is not lib

Directories are not case-sensitive under Windows. OP is using Windows it appears. I still use Windows a lot. I have used Windows for development since 1991.

I also set User variables for PYTHONHOME and PYTHONPATH. Here’s the batch language for that for a cmd.exe window.

set PYTHONPATH=c:\users\chuck\AppData\Local\Programs\Python\Python39\scripts
set PYTHONHOME=c:\users\chuck\AppData\Local\Programs\Python\Python39

I believe PYTHONHOME sets the base directory where libraries are looked for. Maybe OP can double check the Python docs for this.

1 Like

Is this overwriting the current directory or appending to the existing one?