wireservice/csvkit

AttributeError: 'module' object has no attribute 'python_2_unicode_compatible'

gka opened this issue · 13 comments

gka commented

$ head my-valid-data.csv | csvlook

output

Traceback (most recent call last):
  File "/usr/local/bin/csvlook", line 7, in <module>
    from csvkit.utilities.csvlook import launch_new_instance
  File "/usr/local/lib/python2.7/site-packages/csvkit/__init__.py", line 15, in <module>
    import agate
  File "/usr/local/lib/python2.7/site-packages/agate/__init__.py", line 5, in <module>
    from agate.aggregations import *
  File "/usr/local/lib/python2.7/site-packages/agate/aggregations/__init__.py", line 18, in <module>
    from agate.aggregations.base import Aggregation  # noqa
  File "/usr/local/lib/python2.7/site-packages/agate/aggregations/base.py", line 8, in <module>
    @six.python_2_unicode_compatible
AttributeError: 'module' object has no attribute 'python_2_unicode_compatible'

I can't reproduce on Python 2. Please provide a sample file.

Ah, agate only requires an old version of six. To use csvkit before the next release, run pip install --upgrade six.

Upgrading six does not fix this for me

bash-3.2# pip install -U six
Requirement already up-to-date: six in /Library/Python/2.7/site-packages
bash-3.2# pip show six
Name: six
Version: 1.10.0
Summary: Python 2 and 3 compatibility utilities
Home-page: http://pypi.python.org/pypi/six/
Author: Benjamin Peterson
Author-email: benjamin@python.org
License: MIT
Location: /Library/Python/2.7/site-packages
Requires: 
bash-3.2# csvsql
Traceback (most recent call last):
  File "/usr/local/bin/csvsql", line 11, in <module>
    load_entry_point('csvkit==1.0.1', 'console_scripts', 'csvsql')()
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 561, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
    return ep.load()
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2291, in load
    return self.resolve()
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2297, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/Library/Python/2.7/site-packages/csvkit/__init__.py", line 15, in <module>
    import agate
  File "/Library/Python/2.7/site-packages/agate/__init__.py", line 5, in <module>
    from agate.aggregations import *
  File "/Library/Python/2.7/site-packages/agate/aggregations/__init__.py", line 18, in <module>
    from agate.aggregations.base import Aggregation  # noqa
  File "/Library/Python/2.7/site-packages/agate/aggregations/base.py", line 8, in <module>
    @six.python_2_unicode_compatible
AttributeError: 'module' object has no attribute 'python_2_unicode_compatible'
bash-3.2# pip install -U csvkit
Requirement already up-to-date: csvkit in /Library/Python/2.7/site-packages
Requirement already up-to-date: agate>=1.5.5 in /Library/Python/2.7/site-packages (from csvkit)
Requirement already up-to-date: agate-excel>=0.2.0 in /Library/Python/2.7/site-packages (from csvkit)
Requirement already up-to-date: agate-dbf>=0.2.0 in /Library/Python/2.7/site-packages (from csvkit)
Requirement already up-to-date: agate-sql>=0.5.0 in /Library/Python/2.7/site-packages (from csvkit)
Requirement already up-to-date: six>=1.6.1 in /Library/Python/2.7/site-packages (from csvkit)
Requirement already up-to-date: isodate>=0.5.4 in /Library/Python/2.7/site-packages (from agate>=1.5.5->csvkit)
Requirement already up-to-date: awesome-slugify>=1.6.5 in /Library/Python/2.7/site-packages (from agate>=1.5.5->csvkit)
Requirement already up-to-date: parsedatetime>=2.1 in /Library/Python/2.7/site-packages (from agate>=1.5.5->csvkit)
Requirement already up-to-date: Babel>=2.0 in /Library/Python/2.7/site-packages (from agate>=1.5.5->csvkit)
Requirement already up-to-date: leather>=0.3.2 in /Library/Python/2.7/site-packages (from agate>=1.5.5->csvkit)
Requirement already up-to-date: pytimeparse>=1.1.5 in /Library/Python/2.7/site-packages (from agate>=1.5.5->csvkit)
Requirement already up-to-date: openpyxl>=2.3.0 in /Library/Python/2.7/site-packages (from agate-excel>=0.2.0->csvkit)
Requirement already up-to-date: xlrd>=0.9.4 in /Library/Python/2.7/site-packages (from agate-excel>=0.2.0->csvkit)
Requirement already up-to-date: dbfread>=2.0.5 in /Library/Python/2.7/site-packages (from agate-dbf>=0.2.0->csvkit)
Requirement already up-to-date: sqlalchemy>=1.0.8 in /Library/Python/2.7/site-packages (from agate-sql>=0.5.0->csvkit)
Requirement already up-to-date: regex in /Library/Python/2.7/site-packages (from awesome-slugify>=1.6.5->agate>=1.5.5->csvkit)
Requirement already up-to-date: Unidecode<0.05,>=0.04.14 in /Library/Python/2.7/site-packages (from awesome-slugify>=1.6.5->agate>=1.5.5->csvkit)
Requirement already up-to-date: future in /Library/Python/2.7/site-packages (from parsedatetime>=2.1->agate>=1.5.5->csvkit)
Requirement already up-to-date: pytz>=0a in /Library/Python/2.7/site-packages (from Babel>=2.0->agate>=1.5.5->csvkit)
Requirement already up-to-date: jdcal in /Library/Python/2.7/site-packages (from openpyxl>=2.3.0->agate-excel>=0.2.0->csvkit)
Requirement already up-to-date: et_xmlfile in /Library/Python/2.7/site-packages (from openpyxl>=2.3.0->agate-excel>=0.2.0->csvkit)
bash-3.2# 

Any suggestions? OS X 10.10.5.

Hmm, I don't know if it makes any difference, but I'm on OS X 10.12.3 and I always run Python in a virtualenv.

Having the same issue on 10.10.5 with six at 1.10.0
$ pip show six
Name: six
Version: 1.10.0
Summary: Python 2 and 3 compatibility utilities
Home-page: http://pypi.python.org/pypi/six/
Author: Benjamin Peterson
Author-email: benjamin@python.org
License: MIT
Location: /Library/Python/2.7/site-packages
Requires:

$ csvsql
Traceback (most recent call last):
File "/usr/local/bin/csvsql", line 7, in
from csvkit.utilities.csvsql import launch_new_instance
File "/Library/Python/2.7/site-packages/csvkit/init.py", line 15, in
import agate
File "/Library/Python/2.7/site-packages/agate/init.py", line 5, in
from agate.aggregations import *
File "/Library/Python/2.7/site-packages/agate/aggregations/init.py", line 18, in
from agate.aggregations.base import Aggregation # noqa
File "/Library/Python/2.7/site-packages/agate/aggregations/base.py", line 8, in
@six.python_2_unicode_compatible
AttributeError: 'module' object has no attribute 'python_2_unicode_compatible'

@senrabc Run pip show csvkit ?

$ pip show csvkit
Name: csvkit
Version: 1.0.2
Summary: A suite of command-line tools for working with CSV, the king of tabular file formats.
Home-page: http://csvkit.rtfd.org/
Author: Christopher Groskopf
Author-email: chrisgroskopf@gmail.com
License: MIT
Location: /Library/Python/2.7/site-packages
Requires: agate-excel, six, agate, agate-sql, agate-dbf

Hmm. What's python --version?

$ python --version
Python 2.7.10

What's your OS? The only possibility is that Python (when running a csvkit command) is pickup up another version of six installed somewhere else on your system. Are you running this inside a virtual environment? That should also fix it.

OSX 10.10.5

I recommend trying from within a virtual environment (using virtualenv or pyenv) to see if that resolves the issue.

For anyone else who runs into this error on macOS, note that the system installed Python interpreter comes with an old version of six:

>>> import six
# /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py
import six # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.pyc

You can upgrade Python using Homebrew, override the default search path, or live on the edge and delete these files. I upgraded Python via Homebew.

More info here.