edsu / pymarc

process MARC records from Python
http://python.org/pypi/pymarc
Other
253 stars 98 forks source link

six import fails #65

Closed eshellman closed 9 years ago

eshellman commented 10 years ago

for whatever reason, the following statement fails inside a django 1.4.5 project (python 2.7.5)

from six.moves import zip_longest as izip_longest

(in record.py)

Wooble commented 10 years ago

How did you install pymarc? You might need to install six separately if setup.py didn't do it for you.

edsu commented 10 years ago

what is the error?

eshellman commented 10 years ago

2014-10-09 15:58:56,016 ERROR django.request[handle_uncaught_exception]: Internal Server Error: / Traceback (most recent call last): File "/Users/eric/.virtualenvs/regluit/lib/python2.7/site-packages/django/core/handlers/base.py", line 101, in get_response request.path_info) File "/Users/eric/.virtualenvs/regluit/lib/python2.7/site-packages/django/core/urlresolvers.py", line 298, in resolve for pattern in self.url_patterns: File "/Users/eric/.virtualenvs/regluit/lib/python2.7/site-packages/django/core/urlresolvers.py", line 328, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/Users/eric/.virtualenvs/regluit/lib/python2.7/site-packages/django/core/urlresolvers.py", line 323, in urlconf_module self._urlconf_module = import_module(self.urlconf_name) File "/Users/eric/.virtualenvs/regluit/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module import(name) File "/Users/eric/regluit/urls.py", line 5, in from frontend.views import social_auth_reset_password File "/Users/eric/regluit/frontend/views.py", line 68, in from regluit.core import ( File "/Users/eric/regluit/core/marc.py", line 9, in import pymarc File "/Users/eric/.virtualenvs/regluit/lib/python2.7/site-packages/pymarc/init.py", line 62, in from .record import * File "/Users/eric/.virtualenvs/regluit/lib/python2.7/site-packages/pymarc/record.py", line 5, in from six.moves import zip_longest as izip_longest ImportError: cannot import name zip_longest

eshellman commented 10 years ago

pip show six

Name: six Version: 1.8.0 Location: /Users/eric/.virtualenvs/regluit/lib/python2.7/site-packages Requires:

eshellman commented 10 years ago

went back to pymarc 2.9.2 for now. In the 5 minutes I spent on Stack exchange, I got the impression that as a consequence of import magic, the precise syntax for import of six is fragile

eshellman commented 10 years ago

1.4.5

edsu commented 10 years ago

Sorry, I deleted my question after I saw you already reported it :-) I just created a very simple django v1.4.5 application with a single view, that imports pymarc and it works fine.

But I notice this as well https://groups.google.com/forum/#!topic/pymarc/cMWKNYiyDbU

What do you see if you bring up the django shell and try to import like this?

$ ./manage.py shell
Python 2.7.5 (default, Mar  9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from six.moves import zip_longest
eshellman commented 10 years ago

(regluit)gewurztraminer:~ eric$ django-admin.py shell Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54) Type "copyright", "credits" or "license" for more information.

IPython 0.13.2 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details.

In [1]: from six.moves import zip_longest

ImportError Traceback (most recent call last) /Users/eric/.virtualenvs/regluit/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in () ----> 1 from six.moves import zip_longest

ImportError: cannot import name zip_longest

edsu commented 10 years ago

how about just:

import six
eshellman commented 10 years ago

this works: In [1]: import six In [2]: six.moves.zip_longest Out[2]: itertools.izip_longest

(in other words, in my environment, zip_longest isn't a name)

eshellman commented 10 years ago

so I think that

from six.moves import zip_longest as izip_longest

should be replaced with

izip_longest = six.moves.zip_longest

edsu commented 10 years ago

If you do that does it fix your problem? I am unable to replicate the problem you are describing.

eshellman commented 10 years ago

ok, let me fiddle a bit. I was hoping the problem would be obvious.