I'm trying to convert a file.csv to a file.shp through the pyshp / shapefile module. The content of the CSV is:

15.9620040081288987,41.1791119428255143,..., ...

the code I wrote is as follows:

import csv
import shapefile as shp  

points = shp.Writer(shp.POINT)
with open(csv_path + '.csv', 'rb') as csvfile:
     csvreader = csv.DictReader(csvfile)
     header = csvreader.fieldnames
     [points.field(field) for field in header]
     for row in csvreader:
        points.record(*tuple([row[f] for f in header]))

I always used this code without problems, but I don't understand why in this case it return:

Traceback (most recent call last):
  File "my_script.py", line 110, in <module>
    points = shp.Writer(shp.POINT)
  File "/home/username/.local/lib/python2.7/site-packages/shapefile.py", line 1018, in __init__
    self.shp = self.__getFileObj(os.path.splitext(target)[0] + '.shp')
  File "/usr/lib/python2.7/posixpath.py", line 98, in splitext
    return genericpath._splitext(p, sep, altsep, extsep)
  File "/usr/lib/python2.7/genericpath.py", line 99, in _splitext
    sepIndex = p.rfind(sep)
AttributeError: 'int' object has no attribute 'rfind'
  • 2
    Looks like shapefile.Writer() takes the path to the shapefile, not the type of shapefile. shapefile.POINT is likely an integer "constant" representing that geometry type, hence the error complaining about an int
    – mikewatt
    Nov 6, 2018 at 20:27

3 Answers 3


It is a bug in pyshp version 2.0.0 (the version I was using which came out a coupt of days ago). I rolled back to version 1.2.12 and it's working again. More details for it at the link. It will be amended in the next rollout:



This worked for me using the latest version of pyshp and without using GDAL:


points = shp.Writer(shp.POINT)


points = shp.Writer('your_shapefile_name_here', shapeType = shp.POINT)

and (you may not need this)

with open('testing.csv', 'rb') as csvfile:


with open('testing.csv', 'r') as csvfile:

(I personally received an error asking me if I meant to read in text instead of read in binary);

and finally, delete


since your points will be saved as they write, and the shapefile is already named ('your_shapefile_name_here') above.


I solved using the features of ogr2ogr:

import gdal
import os
os.system('ogr2ogr -f "ESRI Shapefile" -a_srs EPSG:4326 '\
          '-oo X_POSSIBLE_NAMES=Lon -oo Y_POSSIBLE_NAMES=Lat '\
          '-oo KEEP_GEOM_COLUMNS=NO '\
          '/path/to/output/shapefile.shp '

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.