4

I am a new programmer who is picking up python. I recently am trying to learn about importing csv files using numpy. Here is my code:

import numpy as np
x = np.loadtxt("abcd.py", delimiter = True, unpack = True)
print(x)

The idle returns me with:

>> True
>> Traceback (most recent call last):
>>  File "C:/Python34/Scripts/a.py", line 1, in <module>
    import numpy as np

>>  File "C:\Python34\lib\site-packages\numpy\__init__.py", line 180, in <module>
    from . import add_newdocs

>>  File "C:\Python34\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc

>>  File "C:\Python34\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *

>>  File "C:\Python34\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx

>>  File "C:\Python34\lib\site-packages\numpy\core\__init__.py", line 14, in <module>
    from . import multiarray

>> SystemError: initialization of multiarray raised unreported exception

Why do I get the this system error and how can I remedy it?

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
Anthony
  • 41
  • 1
  • 2

2 Answers2

4

I have experienced this problem too. This is cuased by a file named "datetime.py" in the same folder (exactly the same problem confronted by Bruce). Actually "datetime" is an existing python module. However, I do not know why running my own script, e.g. plot.py will invoke my datetime.py file (I have seen the output produced by my datetime.py, and there will be an auto-generated datetime.cpython-36.pyc in the __pycache__ folder).

Although I am not clear about how the error is triggered, after I rename my datetime.py file to other names, I can run the plot.py immediately. Therefore, I suggest you check if there are some files whose name collides with the system modules. (P.S. I use the Visual Studio Code to run python.)

Gary Wang
  • 315
  • 4
  • 11
  • 1
    Newer versions of NumPy display the correct exception: `AttributeError: module 'datetime' has no attribute 'datetime_CAPI'`. The reason your file causes this error is explained at https://stackoverflow.com/questions/38540144. – mhsmith Dec 05 '18 at 16:00
3

As there is an error at the import line, your installation of numpy is broken in some way. My guess is that you have installed numpy for python2 but are using python3. You should remove numpy and attempt a complete re-install, taking care to pick the correct version.

There are a few oddities in the code: You are apparently reading a python file, abcd.py, not a csv file. Typically you want to have your data in a csv file.

The delimiter is a string, not a boolean, typically delimiter="," (Documentation)

import numpy as np
x = np.loadtxt("abcd.csv", delimiter = ",", unpack = True)
James K
  • 3,692
  • 1
  • 28
  • 36