I have a python script that i'm trying to run. When i run it from within PyCharm it runs without a problem, but when i run it through the terminal using:
python my_script.py
i get:
Traceback (most recent call last):
File "folder/folder/my_script.py", line 4, in <module>
from my_module import me1, me2, me3
ImportError: No module named my_module
What could be the problem?
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\\')
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
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.
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