0

My directory looks something like

Users
|-Me
|----projectDirectory
|-------file.py
|----Venv\site-packages\
|-------library.py
|-OtherUser\AppData\Local\Programs\Python\Python37\Lib\library.py

file.py tries to import a function from library.py, like so:

from library import Foo

...But, for some reason, it appears to be importing from the OtherUser directory, which leads to problems. I'm using PyCharm, and my configuration is set up correctly to use the interpreter in the "Me" directory. When I middle-click (which brings me to the file being imported from), it takes me to the OtherUser directory. Error messages print that the error is happening in the OtherUser directory.

Despite all this, OTHER files from the "Me" directory are importing from the correct Lib directory. I made sure that the library.py file exists in the venv directory, yet for some reason this file keeps importing from a different user directory.

Does anyone have any suggestions for things I can check?

EDIT: sys.path prints a long list of strings, some go to the projectDirectory, some go to the OtherUser Python directory, and some go to JetBrains.

  • 1
    What is the value of `sys.path`? – Barmar Jul 19 '21 at 17:10
  • If `Venv` is supposed to be a virtual environment, `library.py` should be in `Venv/lib/python/site-packages` or something similar. – chepner Jul 19 '21 at 17:12
  • @Barmar A long list of strings I won't copy-paste here, most of them lead to the "me" project directory, some go to Program Files\\JetBrains\\PyCharm, and a few go to the OtherUser's Python directory. How can I use this information? – NicholasTW Jul 19 '21 at 17:51
  • That's the list of directories to search for modules when importing. If the OtherUser's directory is ahead of yours it will prefer those modules. – Barmar Jul 19 '21 at 17:52
  • @Barmar Is there a way I can change the order? – NicholasTW Jul 19 '21 at 17:58
  • `sys.path = [ what you want the order to be ]` – Barmar Jul 19 '21 at 18:01

0 Answers0