Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dreamhost python3 Django passenger setup import Cookie

I am trying to setup django with python3 on dreamhost.

I have setup a virtualenv as documented by them and installed all the pre-requisites. I have gotten runserver working

The problem comes with passenger setup. The error log shows that I am unable to import a module named Cookie, resulting out of further errors.

This is the traceback:

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'

as you can see the line,

from django.core.wsgi import get_wsgi_application

is failing

on the other hand, when i try it with the python interpreter, it imports correctly.

I have also verified that the same interpreter is being used by passenger by logging the variable

 import sys
 raise Exception(sys.executable)

Any ideas as to the cause of this? I tried logging path, it displays the following

['/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']

which seems fine to me

like image 787
acid_crucifix Avatar asked Jun 13 '26 11:06

acid_crucifix


1 Answers

The instructions in dreamhost wiki works fine. You just need to remove the extra django path in your wsgi config file. It should look like this:

...
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')
...

not like this:

...
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')
...
like image 146
cgl Avatar answered Jun 15 '26 00:06

cgl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!