Trying_hard Trying_hard - 3 months ago 76
Python Question

PyCharm and PYTHONPATH

I am new to PyCharm. I have a directory that I use for my PYTHONPATH.

That directory is c:\test\my\scripts. In this directory I have some modules I import. It works fine in my python shell. My question is how do I add this directory path to PyCharm so I can import what is in that directory.

Answer

you need to make sure each folder that is representing a package is done by putting a __init__.py file which is a empty python file named exactly __init__.py (underscore underscore init underscore underscore) that tells the interpreter that the folder is a python package.

Second thing to look for is that pycharm likes to complain about imported code if PyCharm does not know about that directory. Go into the Project Interpreter Configuration and go to Paths and add the path references that are not in the project or directly under the interpreter.

One other thing to add, is to set the source root of your project code by right clicking the folder that represents your root and clicking the 'Mark Directory as...' > 'Source Root'.