python导入仅在我的生产服务器中不起作用

时间:2016-07-26 13:59:57

标签: python python-import

使用Python 2.7.9(在prod和localhost中) 我过去的代码是这样的

from environment import *

我遇到了一个问题,我向sys.path添加了一些路径,并从另一个environment.py文件中导入导入,而该文件不是我的应用程序。

所以我想明确这个导入并改为

from ApiService.environment import *

在我的localhost中工作但不在生产中。

目录结构相同

ApiService/
   __init__.py 
   environment.py
   main.py

获得

  File "main.py", line 1, in <module>
    from ApiService.environment import *
ImportError: No module named ApiService.environment

仅在我的prod服务器中

我正在localhost和prod

中的ApiService目录中执行应用程序

修改

echo -e 'import sys\nprint(sys.path)' | python

的输出

中的

['', '/Users/partuck/.virtualenvs/dal/lib/python27.zip', '/Users/partuck/.virtualenvs/dal/lib/python2.7', '/Users/partuck/.virtualenvs/dal/lib/python2.7/plat-darwin', '/Users/partuck/.virtualenvs/dal/lib/python2.7/plat-mac', '/Users/partuck/.virtualenvs/dal/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/partuck/.virtualenvs/dal/lib/python2.7/lib-tk', '/Users/partuck/.virtualenvs/dal/lib/python2.7/lib-old', '/Users/partuck/.virtualenvs/dal/lib/python2.7/lib-dynload', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/partuck/.virtualenvs/dal/lib/python2.7/site-packages']

在生产中

['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']
两种环境中的

pwd

localhost:/Volumes/dev/Backend/ApiService

制作:/apps/ApiService

0 个答案:

没有答案