getting sys.path to include the proper root directory on Run


Hi - I'm a novice at PyCharm, just trying out EAP 1.1, after using the NetBeans Python support for quite a while. How does PyCharm determine what it should add to sys.path when it runs a file? It's not doing what I would expect.

My project directory hierarchy looks like this:

(in /home/me)






I have marked MyProject/src as the "Source Root".

If I run PyCharm prepends /home/me/MyProject/src/mymodule to sys.path (twice).

If I run it prepends  /home/me/MyProject/src/mymodule/submodule to sys.path (twice).

But I would expect it to add /home/me/MyProject/src to sys.path. (This is what NetBeans does when you designate a source folder.) has

  from mymodule import Blah

in it, but because of the wrong sys.path, Python can't find mymodule

What's the best way to get the correct sys.path (PYTHONPATH)?

Thanks very much,


Comment actions Permalink

Can someone please comment on why the directory containing the running script is prepended to sys.path? Is this configurable?

Comment actions Permalink

Hi tpetricek! I believe this is a standard behavior in Python, when you call python current working directory is prepended to sys.path. Do you have a more complex case in mind?

Comment actions Permalink

Hi Pavel, I wasn't talking about the current working directory but about the directory which contains the running script. These are two different things. And Pycharm seems to add the containing directory to sys.path, which is not standard behavior. Is this behavior configurable?


Please sign in to leave a comment.