I am trying to understand
PYTHONPATH
related to my project.
My project is in the dir $HOME/Programs/medusa-2.0
, and my source files are in $HOME/Programs/medusa-2.0/medusa
.
I have set my PYTHONPATH in the .bashrc
like this:
export MEDUSA_HOME=$HOME/Programs/medusa-2.0
export PYTHONPATH=${MEDUSA_HOME}/medusa:${PYTHONPATH}
When I try to import a class, from system import error_handler, hello
, I get errors saying that it cannot find the function execute_command
. I don' t understand why I get this error? Is it because I am doing a loop cycle in the imports because execute_command
is in medusasettings
?
ImportError Traceback (most recent call last)
<ipython-input-2-7f959e81c735> in <module>()
----> 1 from medusasystem import error_handler, hello
/home/ubuntu/Programs/medusa-2.0/medusa/medusasystem.py in <module>()
9 from local import lcat
10 import psutil
---> 11 import ranking
12 import settings
13 import simplejson as json
/home/ubuntu/Programs/medusa-2.0/medusa/ranking.py in <module>()
7 import cache
8 from decors import make_verbose
----> 9 from scheduler.predictionranking import get_prediction_metrics
10 from scheduler.randomranking import get_random_metrics
11 from settings import medusa_settings
/home/ubuntu/Programs/medusa-2.0/medusa/scheduler/predictionranking.py in <module>()
6
7 from celery import task
----> 8 import hdfs
9 from networkdaemon import read_network_data
10 from numpylinearregression import estimate_job_execution, calculate_linear_regression_numpy
/home/ubuntu/Programs/medusa-2.0/medusa/hdfs.py in <module>()
4 from hadoopy._hdfs import _checked_hadoop_fs_command
5 from celery import task
----> 6 from medusasystem import execute_command
7 import settings
8
ImportError: cannot import name execute_command
I have tried to launch a python file with python -v
, and I've got this error:
# /home/ubuntu/Programs/medusa-2.0/medusa/hdfs.pyc matches /home/ubuntu/Programs/medusa-2.0/medusa/hdfs.py
import hdfs # precompiled from /home/ubuntu/Programs/medusa-2.0/medusa/hdfs.pyc
Traceback (most recent call last):
File "tests/testHello.py", line 3, in <module>
from medusasystem import error_handler, hello
File "/home/ubuntu/Programs/medusa-2.0/medusa/medusasystem.py", line 11, in <module>
import ranking
File "/home/ubuntu/Programs/medusa-2.0/medusa/ranking.py", line 9, in <module>
from scheduler.predictionranking import get_prediction_metrics
File "/home/ubuntu/Programs/medusa-2.0/medusa/scheduler/predictionranking.py", line 8, in <module>
import hdfs
File "/home/ubuntu/Programs/medusa-2.0/medusa/hdfs.py", line 6, in <module>
from medusasystem import execute_command
ImportError: cannot import name execute_command
- If I launch my virtualenv for my project, shouldn't the PYTHONPATH be defined inside the virtualenv?