I have an own module in my project directory and I import it into my code.
main.py:
from my_module import Test
print(Test.test())
my_module.py:
class Test:
@staticmethod
def test():
return '123'
There is no problem running the code in PyCharm. But when I try to "Execute Selection in Console", I get
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files (x86)\JetBrains\PyCharm 5.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named 'my_module'
How do I import own modules in the PyCharm console?
You can also instruct PyCharm to add source roots to PYTHONPATH
in the Python Console:
For some reason, this option is not activated by default.
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