cenpy-devs / cenpy

Explore and download data from Census APIs
Other
183 stars 44 forks source link

Unable to import cenpy in python 2.7 #13

Closed jGaboardi closed 7 years ago

jGaboardi commented 7 years ago

I am getting 2 different error messages when attempting import cenpy in python 2.7. There is no issue importing cenpy in python 3.5. This seems to have cropped up within the last several weeks.

IPython 5.4.1 -- 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]: import cenpy File "/Users/jgaboardi/anaconda3/envs/py2/lib/python2.7/site-packages/cenpy/tools.py", line 11 def national_to_block(cxn, *columns, wait_by_state=0, ^ SyntaxError: invalid syntax

-----------------

* ***Error 2***
importing directly from the zipped  `cenpy-master` download:

Python 2.7.13 | packaged by conda-forge | (default, May 2 2017, 13:29:36) Type "copyright", "credits" or "license" for more information.

IPython 5.4.1 -- 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]: import cenpy

ImportError Traceback (most recent call last)

in () ----> 1 import cenpy /Users/jgaboardi/Desktop/cenpy-master/cenpy/__init__.py in () 3 4 import cenpy.explorer ----> 5 import cenpy.base 6 from cenpy._version import version as _version 7 from cenpy.tools import _load_sitekey /Users/jgaboardi/Desktop/cenpy-master/cenpy/base.py in () ----> 1 from .remote import APIConnection as Connection /Users/jgaboardi/Desktop/cenpy-master/cenpy/remote.py in () 1 import pandas as pd ----> 2 from json import JSONDecodeError 3 import requests as r 4 import numpy as np 5 from . import explorer as exp ImportError: cannot import name JSONDecodeError ```
ljwolf commented 7 years ago

Those are due to using Python 2.

On Sun, Jul 16, 2017, 5:02 PM James Gaboardi notifications@github.com wrote:

I am getting 2 different error messages when attempting import cenpy in python 2.7. There is no issue importing cenpy in python 3.5. This seems to have cropped up within the last several weeks.

  • Error 1 importing after pip install -U cenpy:

Python 2.7.13 | packaged by conda-forge | (default, May 2 2017, 13:29:36) Type "copyright", "credits" or "license" for more information.

IPython 5.4.1 -- 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]: import cenpy File "/Users/jgaboardi/anaconda3/envs/py2/lib/python2.7/site-packages/cenpy/tools.py", line 11 def national_to_block(cxn, *columns, wait_by_state=0, ^ SyntaxError: invalid syntax


  • Error 2 importing directly from the zipped cenpy-master download:

Python 2.7.13 | packaged by conda-forge | (default, May 2 2017, 13:29:36) Type "copyright", "credits" or "license" for more information.

IPython 5.4.1 -- 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]: import cenpy

ImportError Traceback (most recent call last)

in () ----> 1 import cenpy /Users/jgaboardi/Desktop/cenpy-master/cenpy/__init__.py in () 3 4 import cenpy.explorer ----> 5 import cenpy.base 6 from cenpy._version import version as _version 7 from cenpy.tools import _load_sitekey /Users/jgaboardi/Desktop/cenpy-master/cenpy/base.py in () ----> 1 from .remote import APIConnection as Connection /Users/jgaboardi/Desktop/cenpy-master/cenpy/remote.py in () 1 import pandas as pd ----> 2 from json import JSONDecodeError 3 import requests as r 4 import numpy as np 5 from . import explorer as exp ImportError: cannot import name JSONDecodeError — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread . -- ​ ​​ Levi John Wolf University of Chicago Center for Spatial Data Science | Visiting Fellow Arizona State University | Ph.D. Candidate CARTO, Brooklyn | Summer Spatial Statistical Fellow ljwolf.org
ljwolf commented 7 years ago

To elaborate,

  1. patterns like def function(mandatory_arg, *iterable, keyword=True) are not allowed in Python 2 because it has an incomplete backported implementation of the argument handling available since (I think) 3.4

  2. the JSONDecodeError from the builtin json package is 3-only.