PyCharm and PYTHONPATH

Trying_hard picture Trying_hard · Feb 4, 2015 · Viewed 73.6k times · Source

I am new to PyCharm. I have a directory that I use for my PYTHONPATH: c:\test\my\scripts\. In this directory I have some modules I import. It works fine in my Python shell.

How do I add this directory path to PyCharm so I can import what is in that directory?

Answer

Hendrik F picture Hendrik F · Aug 18, 2016

Out of data, see Duane's answer below.

You need to go to the Main PyCharm Preferences, which will open up a separate window. In the left pane, choose Project:... > Project Interpreter. Now, in the main pane on the right, click the settings symbol (gear symbol) next to the field for "Project Interpreter". Choose More or Show All in the menu that pops up. Now in the final step, pick the interpreter you are using for this project and click on the tree symbol at the bottom of the window (hovering over the symbol reveals it as "Show paths for the selected interpreter"). Add your path by click in the "plus" symbol.

It took me ages to find, so I hope the detailed instructions will help. Further details are available in the PyCharm docs.

It is good practice to have __init__.py in each subfolder of the module you are looking to add, as well as making your project folder a 'Source Root'. Simply right-click on the folder in the path bar and choose 'Mark Directory as ...'