我想了解與我的項目相關的
PYTHONPATH
。試圖瞭解PYTHONPATH
我的項目是在DIR $HOME/Programs/medusa-2.0
,和我的源文件都在$HOME/Programs/medusa-2.0/medusa
。
我已經把我的PYTHONPATH在.bashrc
這樣的:
export MEDUSA_HOME=$HOME/Programs/medusa-2.0
export PYTHONPATH=${MEDUSA_HOME}/medusa:${PYTHONPATH}
當我嘗試導入一個類,from system import error_handler, hello
,我得到的錯誤說,它不能找到函數execute_command
。我不明白爲什麼我會得到這個錯誤?是因爲我在進口中做循環,因爲execute_command
在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
我曾嘗試推出一個Python文件與python -v
,我已經得到了這個錯誤:
# /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
- 如果我啓動我的virtualenv爲我的項目,不應該在virtualenv中定義PYTHONPATH嗎?
如果您在啓動Python時使用'-v'erbose標誌,它會解釋很多關於導入的問題 –
在我的情況下,它並沒有給我很多解釋。你可以檢查我在原帖中添加了什麼。 – xeon123
錯誤部分不是你應該看到的 - 觀看所有的消息。您會看到它與哪些文件匹配。 *你*在任何地方寫了一個名爲'medusasystem.py'或'.pyc'的模塊嗎? –