Python Forum

Full Version: Question about shapefile
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'm using anaconda version 1.8.7
Spyder 3.2.8
Python 3.6

This is my code:

import shapefile

ctr = shapefile.Reader('/Users/oze/SHP/')
I get the following error:
AttributeError: module 'shapefile' has no attribute 'Reader'

Anyone have an idea ?

TNX

Oz
Please, ALWAYS post the entire traceback that you get. We need to see the whole thing - it has important information. Do not just give us the last line.
Take a time to read What to include in a post

In this case, I put my money on your filename to be shapefile.py. Is that the case? This is something we would see in the traceback, if it was the entire one. Rename your file name to be something different from shapefile.py
You're right. It was the name of the file. But even after I changed the problem exists.

The code:
import shapefile
 
ctr = shapefile.Reader('/Users/oze/SHP/')
And...

Error:
runfile('C:/Users/oze/.spyder/test5.py', wdir='C:/Users/oze/.spyder') Traceback (most recent call last): File "<ipython-input-17-723d523bc0ed>", line 1, in <module> runfile('C:/Users/oze/.spyder/test5.py', wdir='C:/Users/oze/.spyder') File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile execfile(filename, namespace) File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/oze/.spyder/test5.py", line 1, in <module> import shapefile ImportError: bad magic number in 'shapefile': b'\x03\xf3\r\n'
https://stackoverflow.com/a/514395/4046632

I would guess ghost shapefile.pyc from the previous run makes a problem