I have the following tree structure in my project:
Cineaste/ ├── cineaste/ │ ├── __init__.py │ ├── metadata_errors.py │ ├── metadata.py │ └── tests/ │ └── __init__.py ├── docs/ ├── LICENSE ├── README.md └── setup.py
metadata.py
imports metadata_errors.py
with the expression:
from .metadata_errors.py import *
Thus setting a relative path to the module in the same directory (notice the dot prefix).
I can run metadata.py
in the PyCharm 2016 editor just fine with the following configuration:
However, with this configuration I cannot debug metadata.py
. PyCharm returns the following error message (partial stack trace):
from .metadata_errors import * SystemError: Parent module '' not loaded, cannot perform relative import
PyCharm debugger is being called like so:
/home/myself/.pyenv/versions/cineaste/bin/python /home/myself/bin/pycharm-2016.1.3/helpers/pydev/pydevd.py --multiproc --module --qt-support --client 127.0.0.1 --port 52790 --file cineaste.metadata
How can I setup this project so that PyCharm is able to run and debug a file that makes relative imports?
If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on the editor and select Debug Python File in Terminal.
Today (PyCharm 2018.3) it is really easy but not obvious. You can choose target to run: script name or module name by pressing the label "Script Path" in edit configuration window:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With