debug a run configuration with a package/module instead of script


With latest pycharm (4.0.4) :

accoding to this stackoverflow response I can run a module (with a somehow trick) instead of a script:

it's ok for the normal run.

but I want also to debug but this fail with :

/home/gstarck/.virtualenvs/surveil/bin/python -m /home/gstarck/work/devtools/pycharm/pycharm-4.0.3/helpers/pydev/ –multiproc –client –port 48055 –file surveil.cmd.api
/home/gstarck/.virtualenvs/surveil/bin/python: Import by filename is not supported.

Process finished with exit code 1

Effectively pydevd expects a real filename for its –file argument.. that's the problem.

If someone has an idea on how to do this ??
Comment actions Permalink

Hi I know it's an old post but did you find a solution? I am having the same problem now.

Comment actions Permalink

You can find a working example of a non-obvious work-around in .  You have to put the command in the "interpreter options" field.

Go to the tracker and vote for better support for this at 


Comment actions Permalink

Vernon Cole's link to Amnong's python_runner worked.

The following solutions found on stackoverlfow and other places and at PyCharm forums all failed to resolve relative imports in run/debug of PyCharm or maybe in PyCharm with multiple windows.


Adding package to PYTHONPATH

import sys
sys.path.insert(0, '../..')

from .relative

from relative  # remove .

if __name__ == "__main__":
import os, sys
# get an absolute path to the directory that contains mypackage
foo_dir = os.path.dirname(os.path.join(os.getcwd(), __file__))
sys.path.append(os.path.normpath(os.path.join(foo_dir, '..', '..')))
from mypackage import bar

import sys
if 'pydevd' in sys.modules:



I had resorted to adding boiler bricks to my code to check if __package__ was None.

python_runner fixed relative imports without the need for any boiler bricks.


Comment actions Permalink

The 2017.3 EPA version of MyCharm added support for this feature. See an official JB response here: 


Please sign in to leave a comment.