0

I've installed some modules with pip, but keep receiving a module not found error when I try to import the modules within a file (not from the terminal). Attempting to import in the terminal works fine.

I'm using a Mac, Python 3. I've already tried manually adding the directory to my PYTHONPATH, with no success. The path has been permanently added as far as I know, as you can see further down, I checked the final path after rebooting terminal.

Threads i've tried:

Modules are installed using pip on OSX but not found when importing

Permanently add a directory to PYTHONPATH?

My imported modules are stored in this directory:

/Library/Python/2.7/site-packages

Running python3 -c 'import sys; print(sys.path)' gives:

['', '/Users/(name)', '/Library/Python/2.7/site-packages', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']

I can't think of what else I could be missing. Any advice would be appreciated, thanks!

helpme
  • 1
  • 1
  • 3
    You are showing path for python2.7 and mentioning python3 for installed packages which you are importing. your packages should be in `/Library/Python/3.*/site-packages`, where * is minor version. – Chandella07 Aug 19 '19 at 16:31
  • Adding to the above comment, make sure you install the libraries on the version of python you intend to use them from. You seem to have multiple python versions installed on your system. Please look at conda environments https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/environments.html or virtual environments https://virtualenv.pypa.io/en/latest/ These make working with multiple python versions/dependencies easier – krzna Aug 19 '19 at 16:45
  • Make sure you're using the right pip for the right Python as well. Best practice is to use `pythonX.Y -m pip install ...` where replace `X.Y` with your actual Python version. This makes explicitly which Python you're installing packages for. Otherwise, there's a million of this kind of question on SO and it's something that can be hard to give a precise answer for without knowing exactly what's going on on your machine. – Iguananaut Aug 19 '19 at 18:28

0 Answers0