Script Running In Pycharm But Not From The Command Line
Solution 1:
There are a few possible things that can be causing this:
- The same python interpreter? Check with
import sys; print(sys.executable)
- Is it the same working directory? Check with
import os; print(os.getcwd())
- Discrepancies in
sys.path
, which is the list python searches sequentially for import locations, can possibly caused by environment variables. Check withimport sys; print(sys.path)
.
Solution 2:
Adding this worked for me:
from os import sys, path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
Solution 3:
As a first step, in PyCharm go to project settings / python interpreter, and note the path. Then compare that to the result of which python
-- do they line up? If not, you need to make them do so.
If that's ok, check what PyCharm defines as your project root in project settings / project structure. Is that the directory where your script is located? If not, you should run the script from that directory or append the directory to the $PYTHONPATH
variable.
Almost definitely, it's one of those two things.
Solution 4:
You might have set some project dependency in Pycharm for module myDependency. You can access the same in Fedora by importing the module explicitly or by creating the egg of that module and installing it. This will then go to python site-packages from where you can refer this dependency.
Post a Comment for "Script Running In Pycharm But Not From The Command Line"