繁体   English   中英

无法从外壳运行python脚本,但能够从eclipse(PyDev)运行

[英]Unable to run python script from shell but able to run it from eclipse(PyDev)

Python版本:2.7操作系统:CentOS

我有一个Python项目,其中多个文件分布在不同的目录中。 我可以通过Eclipse(PyDev)运行它。 但是我无法从linux shell运行它。

目录结构如下所示:

      Projectrepo
          |
          |
        __|__
    src       conf
     |          |
     |          |
 buildexec.py   |
                |
             script_variables, list_of_scripts

buildexec.py是我的主要脚本。 script_variableslist_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')

是一个简单的解决方案! 我的pythonpath指向默认目录/usr/bin/python2.7。 我还使用export PYTHONPATH=/usr/bin/python2.7:/home/tejas/Projectrepo/conf在python路径中添加了用户定义模块的位置

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM