3

当在虚拟环境下和内部导入时,Pandas 正在生成“模块”对象没有属性“核心” 。它可以在虚拟环境内的开发服务器下正常运行。djangomod_wsgidjango

其他模块,例如:numpy 没有问题,所以我认为这意味着虚拟环境已正确设置mod_wsgi。任何意见,将不胜感激。

分期.wsgi

import os
import sys
import site

PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
site_packages = os.path.join(PROJECT_ROOT, 'env/openportfolio/lib/python2.7/site-packages')
site.addsitedir(os.path.abspath(site_packages))
sys.path.insert(0, PROJECT_ROOT)
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
os.environ['DJANGO_SETTINGS_MODULE'] = 'openportfolio.settings_staging'

import pandas #triggers error
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

错误

Traceback (most recent call last):
  File "/usr/local/web/django/www/staging/openportfolio/apache/staging.wsgi", line 22, in <module>
    import pandas
  File "/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages/pandas/__init__.py", line 12, in <module>
    from pandas.core.api import *
  File "/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages/pandas/core/api.py", line 6, in <module>
    import pandas.core.datetools as datetools
  AttributeError: 'module' object has no attribute 'core'  

蟒蛇路径

['/usr/local/web/django/www/staging/openportfolio',
 '/usr/local/web/django/www/staging',
 '/Library/Python/2.7/site-packages/pip-1.0.2-py2.7.egg',
 '/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
 '/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg',
 '/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
 '/Library/Python/2.7/site-packages',
 '/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages']
4

1 回答 1

1

所以事实证明这是一个 Python 路径顺序问题。通过在我的 wsgi 配置文件中运行 sys.path.reverse(),代码现在运行。

由于 Python 路径的顺序,必须首先在虚拟环境中导入内置的 OS X numpy 库,这会导致问题。

'RuntimeError: module compiled against API version 6 but this version of numpy is 4'是我在原始帖子中遗漏的错误行,它可能有助于调试答案。

于 2011-10-24T15:10:26.160 回答