【发布时间】:2015-12-26 19:00:15
【问题描述】:
Python 版本:2.7 操作系统:CentOS
我有一个 python 项目,其中有多个文件分布在不同的目录中。我可以通过 Eclipse(PyDev) 运行它。但是我无法从 linux shell 运行它。
目录结构如下:
Projectrepo
|
|
__|__
src conf
| |
| |
buildexec.py |
|
script_variables, list_of_scripts
buildexec.py 是我的主要脚本。 script_variables 和 list_of_scripts 是我从 buildexec.py 引用的两个模块。
我在我的主脚本中包含了from conf.script_variables import *,当我在 Eclipse 上运行它时它工作正常。但是,当我尝试在 shell 上运行它时,我得到一个错误
'Traceback (most recent call last):
File "buildexec.py", line 6, in <module>
from conf.script_variables import *
ImportError: No module named conf.script_variables'
我已添加 PYTHONPATH=/usr/bin/python2.7 并已将其导出..
另外,在主脚本中,我添加了
sys.path.append('/home/tejas/Projectrepo/conf') 在导入模块之前。
【问题讨论】:
-
为什么在 sys.path 中添加
/home/tejas/Projectrepo/conf而不是/home/tejas/Projectrepo? -
您在这些目录中有 init.py 文件吗?
-
添加它是因为我想引用的模块在
conf目录下。但是,我也只尝试了/home/tejas/Projectrepo,但无法运行。 -
是的,两个目录中都有 init.py 文件。
-
@Tejas 如果你将
append替换为sys.path.insert(0, '/home/tejas/Projectrepo')会怎样?
标签: python shell python-2.7 centos pydev