1

My code is simply the follow and work few days ago:

import pandas as pd

df = pd.read_csv('WORLDBANK-ZAF_MYS_PROP_4044_SEC_MF.csv')
print(df.head())

But now whenever I try to run it by calling python my_io.py on my Mac terminal it generates the following messages:

Bases-MacBook-Pro:data_analysis me$ python my_io.py Traceback (most recent call last): File "my_io.py", line 1, in import pandas as pd File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/init.py", line 13, in import(dependency) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/init.py", line 142, in from . import add_newdocs File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in from numpy.lib import add_newdoc File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/init.py", line 8, in from .type_check import * File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in import numpy.core.numeric as _nx File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/init.py", line 72, in from numpy.testing.nosetester import _numpy_tester File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/init.py", line 12, in from . import decorators as dec File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/decorators.py", line 20, in from .utils import SkipTest, assert_warns File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in from tempfile import mkdtemp, mkstemp File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in import io as _io File "/Users/gongzhuli/Desktop/data_analysis/io.py", line 3, in

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

Can someone please help me, I have no idea what is going on here..

1 Answer 1

1

Your file is called io.py, which is a library module to handle file-like buffers among other things.

pandas imports tempfile which needs it:

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io

and your filename gets in the way of the import chain and prevents import from going through.

Just rename your file with something more specific (like my_io.py for instance?)

Sign up to request clarification or add additional context in comments.

4 Comments

I actually have a bunch of other code all with totally random names within the file that uses pandas module, but none worked today and generating similar error...worked perfectly fine few days ago...
that's still because of that file being imported. Same issue. Rename the file, everything will work all right.
holy *** I am such a stupid head, let's keep this question secret between only me and you lol no one else has seen this question.... the problem was not just with the io.py but it was also caused by pickle.py I made in the same folder and I thought it was not revelant...I really don't know why it did work the other day. damn took me like 2 hours
usually people use csv module and call it csv.py. But there it was more vicious. At least someone saw the question, got 1 upvote :)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.