dreamhost python3 Django乘客设置导入Cookie

时间:2015-02-23 19:30:50

标签: django python-3.x passenger wsgi dreamhost

我正在尝试在dreamhost上使用python3设置django。

我已经设置了他们记录的virtualenv并安装了所有先决条件。我已经运行了runserver

问题在于乘客设置。错误日志显示我无法导入名为Cookie的模块,导致更多错误。

这是追溯:

File "/home/user/path/env/lib/python3.4/imp.py", line 171, in load_source
    module = methods.load()
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "passenger_wsgi.py", line 17, in <module>
    from django.core.wsgi import get_wsgi_application
  File "/home/user/path/env/lib/python3.4/site-packages/django/core/wsgi.py", line 2, in <module>
    from django.core.handlers.wsgi import WSGIHandler
  File "/home/user/path/env/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 11, in <module>
    from django import http
  File "/home/user/path/env/lib/python3.4/site-packages/django/http/__init__.py", line 1, in <module>
    from django.http.cookie import SimpleCookie, parse_cookie
  File "/home/user/path/env/lib/python3.4/site-packages/django/http/cookie.py", line 5, in <module>
    from django.utils.six.moves import http_cookies
  File "/home/user/path/env/lib/python3.4/site-packages/django/utils/six.py", line 90, in __get__
    result = self._resolve()
  File "/home/user/path/env/lib/python3.4/site-packages/django/utils/six.py", line 113, in _resolve
    return _import_module(self.mod)
  File "/home/user/path/env/lib/python3.4/site-packages/django/utils/six.py", line 80, in _import_module
    __import__(name)
  File "/home/user/path/env/lib/python3.4/site-packages/django/http/__init__.py", line 1, in <module>
    from django.http.cookie import SimpleCookie, parse_cookie
ImportError: cannot import name 'SimpleCookie'

你可以看到这一行,

from django.core.wsgi import get_wsgi_application

失败

另一方面,当我尝试使用python解释器时,它会正确导入。

我还通过记录变量

验证乘客正在使用相同的解释器
 import sys
 raise Exception(sys.executable)

关于这个原因的任何想法? 我尝试了记录路径,它显示以下

['/home/user/path/env/lib/python3.4/site-packages', '/home/user/path/env/lib/python3.4/site-packages/django', '/home/user/path/env/bin', '/home/user/path', '/usr/local/dh/passenger/helper-scripts', '/home/user/path/env/lib/python34.zip', '/home/user/path/env/lib/python3.4', '/home/user/path/env/lib/python3.4/plat-linux', '/home/user/path/env/lib/python3.4/lib-dynload', '/home/user/opt/python-3.4.2/lib/python3.4', '/home/user/opt/python-3.4.2/lib/python3.4/plat-linux', '/home/user/path/env/lib/python3.4/site-packages', '/home/user/path', '/home/user/path/git/package']

这对我来说似乎很好

2 个答案:

答案 0 :(得分:1)

The instructions in dreamhost wiki运行正常。您只需要在wsgi配置文件中删除额外的django路径。它应该是这样的:

...
cwd = os.getcwd()
sys.path.append(cwd)
sys.path.append(cwd + '/projectname')  #You must add your project here

sys.path.insert(0,cwd+'/env/bin')
sys.path.insert(0,cwd+'/env/lib/python2.7/site-packages')
...

不喜欢这样:

...
cwd = os.getcwd()
sys.path.append(cwd)
sys.path.append(cwd + '/projectname')  #You must add your project here
sys.path.insert(0,cwd+'/env/lib/python2.7/site-packages/django')
sys.path.insert(0,cwd+'/env/bin')
sys.path.insert(0,cwd+'/env/lib/python2.7/site-packages')
...

答案 1 :(得分:0)

我遇到了同样的问题,以下解决方案适合我。 我使用Python 3.4的Django 1.7,使用Eclipse和PyDev作为我的IDE。

我的解决方案与此主题相关:Import Python module fails (http.cookies)

我做了什么:

  1. 在Eclipse中,转到标签Project/Properties
  2. 选择侧边标签PyDev - PYTHONPATH
  3. 选择External Libraries
  4. 应该有一个类似/.../lib/pythonX.Y/site-packages/django的路径。 删除。 (我使用venv包来创建我的虚拟环境。你的路径可能不同。)

  5. 运行项目并查看它是否有效。

  6. 评论:我认为这确实是一个非常奇怪的问题......与PyDev有关 - 可能与Python3的DjangoProject设置有关。如果这有帮助,请告诉我。