Script running in PyCharm but not from the command line

Asics picture Asics · Apr 10, 2015 · Viewed 14.1k times · Source

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?

Answer

wim picture wim · Apr 10, 2015

There are a few possible things that can be causing this:

  1. The same python interpreter? Check with import sys; print(sys.executable)
  2. Is it the same working directory? Check with import os; print(os.getcwd())
  3. Discrepancies in 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).