When I try to run my program from the PyCharm IDE everything works fine but if I type in Fedora:
python myScript.py
in a shell prompt I get an import error from 1 of the module.
ImportError : No modue named myDependency
What does PyCharm do that allows the interpreter to find my dependencies when launched from the IDE? How can I get my script to find its dependencies so it can be launched with a singe command?
Make sure the file that you want to run is on top. Hit ctrl+shift+F10 to run. The run button should be enabled again.
To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World!
The key combination you are looking for is Ctrl + Shift + F10 . This will run the current script with current being the one displayed in the viewer. Alt+Shift+F10 in PyCharm 2020.3.
There are a few possible things that can be causing this:
import sys; print(sys.executable)
import os; print(os.getcwd())
sys.path
, which is the list python searches sequentially for import locations, can possibly caused by environment variables. Check with import sys; print(sys.path)
. Adding this worked for me:
from os import sys, path sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
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