1

I've read through a few threads with questions similar to this (this one in particular), and tried out some solutions but not succeeded yet.

I want to include python's default site-packages directory in the sys.path, for all scripts in a project. In my case this path is in my user directory:

.../Library/Python/3.7/lib/python/site-packages/

That is where packages all are installed to (e.g. scipy), and it seems inefficient to have to add sys.path.append at the start of every script (as I've seen others say too).

I tried the solution proposed here - namely adding the above path to the list project interpreter's paths (seen at the bottom):

screenshot

Red lines in the screenshot are removing some personal/work directory names. The third line is the ...lib/python3.7/site-packages directory in the PyCharm project's directory.

After OKing these new settings, in the terminal under the same PyCharm project, if you do:

import sys
sys.path

it returns:

['',
'/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip',
'/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
'/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload',
<the path for `...lib/python3.7/site-packages` in PyCharm Project's directory>]

i.e. the path I just added isn't there, and import scipy for example doesn't work. (I tried closing/reopening PyCharm in case that did anything, but no luck.)

It seems like the person in that post was asking the same thing as this, and it worked for them. Am I doing something wrong, or just misunderstanding?

Chris Browne
  • 449
  • 5
  • 14
  • Is there a reason why you wanted to do local files and not use something like `pipenv` to localize your dependencies to your project? – Mike Tung Nov 30 '18 at 14:39
  • Hi Mike, I'm new to Python so haven't seen `pipenv` - a quick read of the docs and it seems quite out of my depth! The main objective here is to be able to import a few modules that are in this default python directory, without needing to append to `sys.path` in each script. – Chris Browne Nov 30 '18 at 14:43
  • 1
    I would recommend using pipenv because it'll allow you finer control of your imports per project. Also it will eliminate the need to do what you are doing and just do `import scipy` without a worry. – Mike Tung Nov 30 '18 at 15:02
  • Thanks for the recommendation, I'll look into it – Chris Browne Nov 30 '18 at 16:02

0 Answers0