Weird that under Python 3.4 runtime you can import from 2.7

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

Interesting:

Weird that under Python 3.4 runtime you can import from 2.7. That should not be possible for all those sanity reasons.

Because allowing that means:

Thanks. I might miss something obvious but when using gunicorn MYPROJECT.wsgi:application i get:

File “/virtualenv/lib/python3.4/site-packages/django/utils/timezone.py”, line 13, in
import pytz
File “/virtualenv/lib/python3.4/site-packages/pytz/__init__.py”, line 37, in
from pytz.lazy import LazyDict, LazyList, LazySet
File “/virtualenv/lib/python3.4/site-packages/pytz/lazy.py”, line 3, in
from UserDict import DictMixin
File “/usr/lib/python2.7/UserDict.py”, line 134
raise TypeError, “pop expected at most 2 arguments, got “\
^
SyntaxError: invalid syntax
Obviously the problem is that my Virtualenv has /usr/lib/python2.7 in its Path. But i don’t find the right place to change that. I have no PYTHONPATH environment variable.

and finally:

I found my problem. There was a sys.path.append with python 2.7 in my wsgi which was quite outdated.

Post external references

  1. 1
    https://github.com/benoitc/gunicorn/issues/705
Source