Python - "No module named my_module" in terminal, but not in PyCharm

adding the following code to the head of the script did the trick for me:

import sys
sys.path.append('C:\\path\to\\my\\awesome\\project\\')

Another reason might be you had started your project in pycharm with virtual enviroment.

If it is the case go to your projects venv\Scripts folder via your terminal and run activate.bat .

You will see "(venv)" on leftmost in your terminal line. Then go to your project folder and run

python my_script.py

Now it should work.


The PYTHONPATH in your terminal environment doesn't contain 'my_module'.

Configure the PYTHONPATH to include the directory containing your module

It works in pycharm because it sets up the path for you automagically.

Learn about the module search path

Tags:

Python

Pycharm