Reputation: 9501
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 well in my Python shell.
How do I add this directory path to PyCharm, so I can import what is in that directory?
Upvotes: 135
Views: 167588
Reputation: 5567
As of PyCharm 2023.3.3, adding PYTHONPATH=foo:bar:baz
to the "Environment Variables" section of a "Run Configuration" does not work. One must go to the "Project Structure" item under the "Project: foobar" item in the "Settings Dialog" and "Add Content Root," e.g. .
Upvotes: 1
Reputation: 3930
Out of date. See Duane's answer below for pycharm version newer than 2019.2.
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 ...'
Upvotes: 195
Reputation: 69675
The following answer is for PyCharm 2022.1.3+ (Professional Edition).
Click on the three vertical dots and the on Show All...
Choose your interpreter and then click on the directory structure icon
Click on the +
icon and add the path you need to add to PYTHONPATH
.
That's it!
Upvotes: 26
Reputation: 2020
In PyCharm Community 2019.2/2019.3 (and probably other versions), you can simply:
Modules within that folder will now be available for import. Any number of folders can be so marked.
Upvotes: 62
Reputation: 5140
For Pycharm Community 2019.3
Upvotes: 108