eduncan911
eduncan911

Reputation: 17604

six: cannot import name python_2_unicode_compatible

With six 1.10.0 installed under Python and pip 2.6, an old Django 1.0.4 app is not able to import python_2_unicode_compatible even though it finds six 1.10.0 just fine:

>>> import six
>>> six.__version__
'1.10.0'
>>> from six import python_2_unicode_compatible
>>> 

I've confirmed with python code within the app that it does indeed have access to six:

['appdirs==1.4.3', 'argparse==1.4.0', 'astkit==0.5.4', 'beautifulsoup==3.2.1',
'coverage==4.3.4', 'django-cms==2.0.0a0', 'django==1.0.4', 'dnspython==1.12.0',
'flup==1.0.2', 'importlib==1.0.4', 'iniparse==0.3.1', 'instrumental==0.5.3',
'mako==1.0.6', 'markupsafe==1.0', 'minimock==1.2.8', 'mysql-python==1.2.5',
'nose==1.3.7', 'packaging==16.8', 'pillow==3.4.2', 'pip==9.0.1', 'pluggy==0.4.0',
'py==1.4.33', 'pyparsing==2.2.0', 'python-dateutil==2.6.0', 'pyzor==1.0.0',
'setuptools==35.0.1', 'six==1.10.0', 'sorl-thumbnail==12.3', 'tox==2.7.0',
'uwsgi==2.0.15','virtualenv==15.1.0', 'wheel==0.29.0']

I am tasked to move a very old site that was running django 1.0.4 (you read that right, 1.0.4) and django_cms 2.0.0 Alpha to a new server. The old server croaked, so all I have is the backup of the main website files and dependencies that were installed long ago.

I am Dockerizing it to help document and deploy this in the future.

Ubuntu 14.04
Python 2.6 (same results with 2.7)
Django 1.0.4 (installed via local zip)
django_cms 2.0.0a0 (installed via local zip)

I have tried Apache mod_wsgi, gunicorn (pip2.6 installed) and currently using uwsgi (preferred, pip2.6 installed) to load the app.

Nginx is running in another Docker container with proxy_pass, and will the frontend proxy and TLS.

uwsgi starts the site up with the custom wsgi.

Upon loading the / index page, I had many import errors. Slowly, I am resolving each and every one of them (mostly related to the Django "MIDDLEWARE_CLASSES", which I have yet to find their definition).

I am currently stuck on the following error:

Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 230, in __call__
    self.load_middleware()
  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 41, in load_middleware
    raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e)
django.core.exceptions.ImproperlyConfigured: Error importing middleware cms.middleware.user: "cannot import name python_2_unicode_compatible"

uwsgi starts up with the specified python2.6 just fine:

web_1    | [uWSGI] getting INI configuration from uwsgi.ini
web_1    | *** Starting uWSGI 2.0.15 (64bit) on [Wed Apr 26 16:27:43 2017] ***
web_1    | Python version: 2.6.9 (default, Oct 22 2014, 19:53:49)  [GCC 4.8.2]
web_1    | Python main interpreter initialized at 0xef1050
web_1    | python threads support enabled

Also, python2.7 was originally configured and had the exact same error. I thought I read where python_2_unicode_compatible was deprecated in 2.7 or something, so I went back to the original version the site was running under.


Do I need to install virtualenv? I don't usually do it under Docker, and just install everything globally. I can't see how that would make a difference.

If six was not found, wouldn't I get an error that it could not import six, instead of python_2_unicode_compatible?

Upvotes: 2

Views: 5982

Answers (1)

Alasdair
Alasdair

Reputation: 308829

The python_2_unicode_compatible method was originally in Django, then added to six in 1.9.

One of your installed packages may be trying to import python_2_unicode_compatible from django.utils.encoding, rather than from the six package.

Upvotes: 3

Related Questions