initialization of multiarray raised unreported exception python - python

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?

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.)

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)

Related

AttributeError: partially initialized module x has no attribute y (most likely due to a circular import)

I want to use pandas to process a csv file. The main job is to duplicate a column, so I name the script file as copy.py.
import pandas as pd
df = pd.read_csv('latex.csv')
However, when I execute the file, it gets the error
$ python copy.py
Traceback (most recent call last):
File "~/sourcecode/rime-math/copy.py", line 1, in <module>
import pandas as pd
import pandas as pd
File "~/.local/lib/python3.10/site-packages/pandas/__init__.py", line 50, in <module>
from pandas.core.api import (
File "~/.local/lib/python3.10/site-packages/pandas/core/api.py", line 48, in <module>
from pandas.core.groupby import (
File "~/.local/lib/python3.10/site-packages/pandas/core/groupby/__init__.py", line 1, in <module>
from pandas.core.groupby.generic import (
File "~/.local/lib/python3.10/site-packages/pandas/core/groupby/generic.py", line 73, in <module>
from pandas.core.frame import DataFrame
File "~/.local/lib/python3.10/site-packages/pandas/core/frame.py", line 129, in <module>
from pandas.core import (
File "~/.local/lib/python3.10/site-packages/pandas/core/generic.py", line 122, in <module>
from pandas.core.describe import describe_ndframe
File "~/.local/lib/python3.10/site-packages/pandas/core/describe.py", line 37, in <module>
from pandas.core.reshape.concat import concat
File "~/.local/lib/python3.10/site-packages/pandas/core/reshape/concat.py", line 45, in <module>
from pandas.core.internals import concatenate_managers
File "~/.local/lib/python3.10/site-packages/pandas/core/internals/__init__.py", line 17, in <module>
from pandas.core.internals.concat import concatenate_managers
File "~/.local/lib/python3.10/site-packages/pandas/core/internals/concat.py", line 3, in <module>
import copy
File "~/sourcecode/rime-math/copy.py", line 4, in <module>
df = pd.read_csv('latex.csv')
AttributeError: partially initialized module 'pandas' has no attribute 'read_csv' (most likely due to a circular import)
The problem is that the name of your script file is collision with the file one of your module wants to import.
Put attention on the last 5 lines of the traceback since it is near line where error occurs:
File "~/.local/lib/python3.10/site-packages/pandas/core/internals/concat.py", line 3, in <module>
import copy
File "~/sourcecode/rime-math/copy.py", line 4, in <module>
df = pd.read_csv('latex.csv')
AttributeError: partially initialized module 'pandas' has no attribute 'read_csv' (most likely due to a circular import)
Look at the first 2 lines, it means pandas module need to import copy module at somewhere.
According to The Module Search Path, Python interpreter will search copy module in built-in modules, current directory, PYTHONPATH etc. in order.
Apparently there is no built-in modules named copy in Python, so the interpreter will then look at the files under current directory and find there is copy.py.
The content of copy.py is just one line: df = pd.read_csv(). It means we need to use pandas module. However, we are just on the way importing pandas. Pandas here is only partially initialized, that's why you see that information in backtrace.
To solve this is easy, rename the script file copy.py to some others is ok.

ValueError: source code string cannot contain null bytes - Error after scipy.io import

After updating scipy, numpy and pandas to the newest versions, I receive the following error whenever I attempt to run my code on a Windows 10 machine with Python 3.7.4:
Traceback (most recent call last):
...
File "Path\To\MyClass.py", line 3, in <module>
import scipy.io as sio
File "Path\To\Anaconda\lib\site-packages\scipy\__init__.py", line 68, in <module>
from ._lib.deprecation import _deprecated
File "Path\To\Anaconda\lib\site-packages\scipy\_lib\__init__.py", line 12, in <module>
from scipy._lib._testutils import PytestTester
ValueError: source code string cannot contain null bytes
This is how the last file looks like:
"""
Module containing private utility functions
===========================================
The ``scipy._lib`` namespace is empty (for now). Tests for all
utilities in submodules of ``_lib`` can be run with::
from scipy import _lib
_lib.test()
"""
from scipy._lib._testutils import PytestTester
test = PytestTester(__name__)
del PytestTester
Am I running into a bug or is my setup broken?
I managed to solve this issue by reinstalling Anaconda. I still don't know the source of the problem though.

Getting the following error: AttributeError: module 'pandas' has no attribute 'read_csv'

I have looked at several other similar questions but their fixes are not working for me. I am running my script in a conda venv but I already installed pandas within said environment. I will show my code and the error I get when running from the terminal. Obviously, the directory of the virtual environment is not the same as the directory of my css file, which is why I give the file path to the file. I must add that within VS Code, I am able to get the data set and add items to the list I created (although the while loop is not currently working). Can anyone help?
import pandas as pd
import random
data_set = pd.read_csv("/Users/rickvillanueva/Documents/Myron/dated_random.csv")
random_data = data_set.MYRON_ACCT
random_names = []
random_gatherer = True
#Gathering random account numbers
while random_gatherer:
one = random.choice(random_data)
random_names.append(one)
if len(random_names) < 50:
random_gatherer = True
continue
else:
break
len(random_names)
print(random_names)
Error I get in terminal:
Traceback (most recent call last):
File "random.py", line 1, in <module>
import pandas as pd
File "/Users/rickvillanueva/opt/anaconda3/lib/python3.7/site-packages/pandas/__init__.py", line 11, in <module>
__import__(dependency)
File "/Users/rickvillanueva/opt/anaconda3/lib/python3.7/site-packages/numpy/__init__.py", line 152, in <module>
from . import random
File "/Users/rickvillanueva/opt/anaconda3/lib/python3.7/site-packages/numpy/random/__init__.py", line 181, in <module>
from . import _pickle
File "/Users/rickvillanueva/opt/anaconda3/lib/python3.7/site-packages/numpy/random/_pickle.py", line 1, in <module>
from .mtrand import RandomState
File "_bit_generator.pxd", line 14, in init numpy.random.mtrand
File "_bit_generator.pyx", line 40, in init numpy.random._bit_generator
File "/Users/rickvillanueva/opt/anaconda3/lib/python3.7/secrets.py", line 20, in <module>
from random import SystemRandom
File "/Users/rickvillanueva/Documents/Myron/random.py", line 5, in <module>
data_set = pd.read_csv("/Users/rickvillanueva/Documents/Myron/dated_random.csv")
AttributeError: module 'pandas' has no attribute 'read_csv'

Error while importing psychopy.iohub

I'm trying to use iohub to incorporate Eye-Tracking (SR-research Eye-Link) support in my experiment in Psychopy.
I'm using python2.7 on a Mac.
However, I get an error while I'm trying to import it:
from psychopy.iohub.datastore.util import ExperimentDataAccessUtility
File "/Users/.../ETUtilities.py", line 2, in <module>
from psychopy.iohub.datastore.util import ExperimentDataAccessUtility
File "/Library/Python/2.7/site-packages/PsychoPy-1.82.01-py2.7.egg/psychopy/iohub/datastore/__init__.py", line 16, in <module>
import tables
File "/Library/Python/2.7/site-packages/tables/__init__.py", line 90, in <module>
from .utilsextension import (
ImportError: cannot import name get_pytables_version
I tried to install this module but found nothing.
Any idea?
You mean you didn't find the module?
https://www.google.com/search?source=hp&ei=bGw7WtaDCMbDgAb6qo3gAw&q=pytables&oq=pytables&gs_l=psy-ab.3..35i39k1l2j0l8.592.592.0.784.2.1.0.0.0.0.125.125.0j1.1.0.crnk_dmh...0...1.2.64.psy-ab..1.1.124.0...0.LZUJpfdZBYE

Pandas import error with python 2.7

I'm creating a very simple Python program which imports ExxonMobil's stock price between two data from Google Finance.
Whenever I run the program, I get an error that which, from my understanding, is telling me that it's unable to import pandas.
Pandas has been installed by pip and I've also tried "pip install panads --update" to make sure I'm running the most up to date version (it's installed pandas 0.21.0). Same with pandas-datareader but still no luck. What I'd expect to see is that it prints out the first 5 rows of data.
I'm running Python 2.7 and it's in a virtualenv.
Thanks for any help in advance and the code is below:
import datetime
import pandas
from pandas_datareader import data
start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2015, 8, 22)
df = data.DataReader("XOM", "google", start, end)
print df.head()
Error output:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/lcc/virtualenv/matplotlib/pandas.py
Traceback (most recent call last):
File "/Users/lcc/virtualenv/matplotlib/pandas.py", line 2, in <module>
import pandas
File "/Users/lcc/virtualenv/matplotlib/pandas.py", line 3, in <module>
from pandas_datareader import data
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas_datareader/__init__.py", line 3, in <module>
from .data import (get_components_yahoo, get_data_famafrench, get_data_google, get_data_yahoo, get_data_enigma, # noqa
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas_datareader/data.py", line 7, in <module>
from pandas_datareader.google.daily import GoogleDailyReader
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas_datareader/google/daily.py", line 1, in <module>
from pandas_datareader.base import _DailyBaseReader
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas_datareader/base.py", line 7, in <module>
import pandas.compat as compat
ImportError: No module named compat
Process finished with exit code 1
Check what is written in the error traceback:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas_datareader/base.py", line 7, in <module>
import pandas.compat as compat
pandas_datareader/base.py calls (imports) pandas.compat
you named your script pandas.py - that has shadowed the Pandas module and your script doesn't contain compat.
Solution:
Rename /Users/lcc/virtualenv/matplotlib/pandas.py to something that does NOT duplicate/shadow any of Python module names.
For example: /Users/lcc/virtualenv/matplotlib/my_first_pandas_prog.py

Categories

Resources