GeospatialPython / pyshp

This library reads and writes ESRI Shapefiles in pure Python.
MIT License
1.1k stars 260 forks source link

How to install the version2.0 pyshp? #169

Closed Chenghui123 closed 5 years ago

Chenghui123 commented 6 years ago

How to install the version2.0 pyshp? I replace the shapefile.py document, then it gives a error. image So, what should i do?

micahcochran commented 6 years ago

You should install this package using: $ pip install pyshp

I suspect this is another instance of issue #139 . What are the field names in the shapefile "02_ZA03341003"?

Chenghui123 commented 6 years ago

I use pip install pyshp to install, then it installed the version of 1.2.12. Then I replace the shapefile.py docunment with this https://github.com/GeospatialPython/pyshp/blob/master/shapefile.py. It is correct?

This is the field names in the shapefile "02_ZA03341003"

image

micahcochran commented 6 years ago

Since 2.0 hasn't been released, download the ZIP file of the github repository (which should download the file "pyshp-master.zip").

Then run, pip install pyshp-master.zip

Pyshp is pretty simple, so your approach of copying over the old file shapefile.py might work.

With regard to those field names it similar to #139 (which deals with creating a new shapefile with unicode field names), but in this case you want to read a shapefile with unicode field names. According to the xBase spec, the field names are only suppose to be ASCII.

karimbahgat commented 6 years ago

PyShp v2.0.0 is now officially released on PyPI, so a 'pip install pyshp' should work as well. As for the problem however, upgrading will not fix the problem with non-ascii characters as field names. As detailed in #139, the shapefile/dbf spec only allows ascii characters in field names, and this was only enforced in more recent versions including 2.0.0.

However, I am starting to consider the idea to at least allow reading such shapefiles, and possibly also writing them combined with a warning. Especially so if other popular GIS tools/software also support/handle such files. If you would like to see this feature or have any thoughts, please comment in #139.

sebastic commented 6 years ago

PyShp fails to build from source with Python 2.7 due to this issue:

I: pybuild base:184: python2.7 setup.py clean 
running clean
removing '/home/bas/git/pkg-grass/pyshp/.pybuild/pythonX.Y_2.7/build' (and everything under it)
'build/bdist.linux-x86_64' does not exist -- can't clean it
'build/scripts-2.7' does not exist -- can't clean it
I: pybuild base:184: python3.5 setup.py clean 
Traceback (most recent call last):
  File "setup.py", line 6, in <module>
    long_description=open('README.md').read(),
  File "/usr/lib/python3.5/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 37236: ordinal not in range(128)
E: pybuild pybuild:283: clean: plugin distutils failed with: exit code=1: python3.5 setup.py clean 

The following lines seems to be problematic due to not containing ASCII characters:

1018         >>> r.record(0) == [2, u'Ñandú']
...
1033         >>> r.record(0) == [2, u'Ñandú']
...
1043         >>> r.record(0) == [2, u'�and�']

setup.py should probably read the README.md differently when executed with Python 2.7.

megies commented 6 years ago

@sebastic I can't reproduce your problem. In any case it seems it's failing for you on Python 3.5, not Python 2.7.

Curious @sebastic, are you packaging for Debian/Ubuntu?

sebastic commented 6 years ago

Curious @sebastic, are you packaging for Debian/Ubuntu?

Yes, the build failure occurred when updating the pyshp Debian package to 2.0.0.

The changes in #171 fix that build failure and are included as a patch in the Debian package.

Chenghui123 commented 6 years ago

I try to install PyShp v2.0.0 with pip install pyshp, then I got this error.

image

megies commented 6 years ago

@Chenghui123 you should be able to circumvent this problem by setting the locale in that shell before executing pip to utf-8. I have no idea how to do that on windows, but it should be easy to find out on the internet. Here's an example for Linux:

~$ export LC_ALL='C'
~$ pip install --no-cache-dir pyshp
Collecting pyshp
  Downloading https://files.pythonhosted.org/packages/da/65/48606341aa058adcb596165c5047fc0df93c6a06d9ea1322059c9be78591/pyshp-2.0.0.tar.gz (213kB)
    100% |################################| 215kB 11.5MB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-zcsgrc43/pyshp/setup.py", line 6, in <module>
        long_description=open('README.md').read(),
      File "/home/megies/anaconda/envs/pyshp_test3/lib/python3.6/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 37236: ordinal not in range(128)

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-zcsgrc43/pyshp/
~$ export LC_ALL='en_US.utf8'
~$ pip install --no-cache-dir pyshp
Collecting pyshp
  Downloading https://files.pythonhosted.org/packages/da/65/48606341aa058adcb596165c5047fc0df93c6a06d9ea1322059c9be78591/pyshp-2.0.0.tar.gz (213kB)
    100% |████████████████████████████████| 215kB 11.2MB/s 
Installing collected packages: pyshp
  Running setup.py install for pyshp ... done
Successfully installed pyshp-2.0.0
micahcochran commented 6 years ago

@Chenghui123 Does the release of version 2.0.1 fix the problem?

megies commented 5 years ago

I believe it should

karimbahgat commented 5 years ago

Marking this as closed since 2.0.1 should fix it.