简体   繁体   中英

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

Python version:2.7 OS: CentOS

I have a python project with multiple files spread across different directories. I am able to run this through Eclipse(PyDev). However I am unable to run it from linux shell.

The directory structure looks like this:

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

buildexec.py is my main script. script_variables and list_of_scripts are two modules which I am referencing from buildexec.py.

I have included from conf.script_variables import * in my main script and it is working fine when I run it on eclipse. But, when I try to run it on shell, I get an error

'Traceback (most recent call last): File "buildexec.py", line 6, in <module> from conf.script_variables import * ImportError: No module named conf.script_variables'

I have added PYTHONPATH=/usr/bin/python2.7 and have exported it..

Also, in the main script, I have added

sys.path.append('/home/tejas/Projectrepo/conf') before importing the modules.

Was a simple solution! My pythonpath was pointing to the default directory /usr/bin/python2.7. I added the location of the user defined modules also in the python path using export PYTHONPATH=/usr/bin/python2.7:/home/tejas/Projectrepo/conf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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