I use pandas regularly. I restarted my computer recently and now I get the following error every time I try to import pandas. This does not happen with other packages. Any suggestions?
import pandas as pd
Traceback (most recent call last):
File "C:\Users\UserName\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
import pandas as pd
File "C:\Users\UserName\Anaconda3\lib\site-packages\pandas__init__.py", line 42, in
from pandas.core.api import *
File "C:\Users\UserName\Anaconda3\lib\site-packages\pandas\core\api.py", line 10, in
from pandas.core.groupby import Grouper
File "C:\Users\UserName\Anaconda3\lib\site-packages\pandas\core\groupby.py", line 49, in
from pandas.core.frame import DataFrame
File "C:\Users\UserName\Anaconda3\lib\site-packages\pandas\core\frame.py", line 4262
df ignore_failures=ignore_failures)
Update: I uninstalled anaconda and reinstalled and everything is now working.
Related
I was just getting started with PyCharm and python for statistics.
And I got this error:
ImportError: cannot import name 'int' from 'numpy' (/home/tetiana/.local/lib/python3.8/site-packages/numpy/init.py)
Full traceback looks like this:
Traceback (most recent call last):
File "/home/tetiana/forVScode/python/first/first_try.py", line 1, in
from scipy import stats
File "/usr/lib/python3/dist-packages/scipy/stats/init.py", line 379, in
from .stats import *
File "/usr/lib/python3/dist-packages/scipy/stats/stats.py", line 180, in
import scipy.special as special
File "/usr/lib/python3/dist-packages/scipy/special/init.py", line 643, in
from .basic import *
File "/usr/lib/python3/dist-packages/scipy/special/basic.py", line 19, in
from . import orthogonal
File "/usr/lib/python3/dist-packages/scipy/special/orthogonal.py", line 81, in
from numpy import (exp, inf, pi, sqrt, floor, sin, cos, around, int,
ImportError: cannot import name 'int' from 'numpy' (/home/tetiana/.local/lib/python3.8/site-packages/numpy/init.py)
Process finished with exit code 1
How can I fix it?
Here is my code:
from scipy import stats
import pandas as pd
state = pd.read_csv('state_murder_rate_test_table.csv')
state['Population'].mean()
stats.trim_mean(state['Population'], 0.1)
state['Population'].median()
I checked whether the Python versions in os and in the project match and they are. I have python 3.8.10 and my os is Ubuntu 20.04
Referring to the current numpy documentation, there exists no type called numpy.int that you can import. I believe that the type you wanna import is numpy.integer or numpy.int_.
The code you provided does not have any statement like: from numpy import int. If you could provide a full traceback error, it'll be easier to see where the error stems from.
I hope this answer will be somewhat useful.
Since two days I get the following errors in all my script wherever I am importing pandas :
Example:
Traceback (most recent call last):
File "session_id.py", line 3, in <module>
import pandas as pd
File "C:\Users\USER\anaconda3\envs\virtual_workspace\lib\site-packages\pandas\__init__.py", line 22, in <module>
from pandas.compat import (
File "C:\Users\USER\anaconda3\envs\virtual_workspace\lib\site-packages\pandas\compat\__init__.py", line 15, in <module>
from pandas.compat.numpy import (
File "C:\Users\USER\anaconda3\envs\virtual_workspace\lib\site-packages\pandas\compat\numpy\__init__.py", line 7, in <module>
from pandas.util.version import Version
File "C:\Users\USER\anaconda3\envs\virtual_workspace\lib\site-packages\pandas\util\__init__.py", line 1, in <module>
from pandas.util._decorators import ( # noqa
File "C:\Users\USER\anaconda3\envs\virtual_workspace\lib\site-packages\pandas\util\_decorators.py", line 14, in <module>
from pandas._libs.properties import cache_readonly # noqa
File "C:\Users\USER\anaconda3\envs\virtual_workspace\lib\site-packages\pandas\_libs\__init__.py", line 13, in <module>
from pandas._libs.interval import Interval
File "pandas\_libs\interval.pyx", line 1, in init pandas._libs.interval
File "pandas\_libs\hashtable.pyx", line 1, in init pandas._libs.hashtable
File "pandas\_libs\missing.pyx", line 1, in init pandas._libs.missing
File "C:\Users\USER\anaconda3\envs\virtual_workspace\lib\site-packages\pandas\_libs\tslibs\__init__.py", line 31, in <module>
from pandas._libs.tslibs.conversion import (
File "pandas\_libs\tslibs\conversion.pyx", line 1, in init pandas._libs.tslibs.conversion
File "pandas\_libs\tslibs\timezones.pyx", line 14, in init pandas._libs.tslibs.timezones
File "C:\Users\USER\anaconda3\envs\virtual_workspace\lib\site-packages\dateutil\tz.py", line 78
`self._name`,
^
SyntaxError: invalid syntax
My python version is 3.8.10
I have tried to solve the issue by :
upgrading pandas
upgrading pip
upgrading anaconda
Thanks for your help
I have been working with a script using pandas, numpy, and scikit-learn that worked just fine.
Out of the blue (for sure I did something, but I do not know what) I am getting this error message:
C:\Users\xx\Anaconda3\python.exe
C:/Users/xxxx/create_predictions_2.py
Traceback (most recent call last):
File "C:/Users/xxxx/create_predictions_2.py", line 5, in <module>
import numpy as np
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\__init__.py", line 185, in <module>
from . import add_newdocs
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 9, in <module>
from . import numerictypes as nt
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\core\numerictypes.py", line 968, in <module>
_register_types()
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\core\numerictypes.py", line 965, in _register_types
numbers.Integral.register(integer)
AttributeError: 'module' object has no attribute 'Integral'
Process finished with exit code 1
I am doing the following imports
import numpy as np
import pandas as pd
import xgboost as xgb
import os
from sklearn.preprocessing import LabelEncoder
As you can see, I am using Anaconda on python 3.
Any hints?
i think the issue is due to some jython calls means you tried to create a jython program executed python code in java then without destroying the process you tried to call a python program from python interpreter.
I am trying to use matplotlib for real-time analysis from ECG-signals, but the problem starts even before.
I use the PyCharm IDE, currently working with Python 3.3 and my os is Windows 8.1.
For Matplotlib I downloaded matplotlib and the dependencies (numpy, six, dateutil, pyparsing, pytz) from here (the versions for Python 3.3): http://www.lfd.uci.edu/~gohlke/pythonlibs/ and installed it in the Python33 folder.
Now if I try:
from matplotlib.pyplot import plot, show
plot(range(10))
show()
or:
import pylab
from pylab import *
xAchse=pylab.arange(0,100,1)
yAchse=pylab.array([0]*100)
fig = pylab.figure(1)
ax = fig.add_subplot(111)
ax.grid(True)
ax.set_title("Realtime Waveform Plot")
ax.set_xlabel("Time")
ax.set_ylabel("Amplitude")
ax.axis([0,100,-1.5,1.5])
line1=ax.plot(xAchse,yAchse,'-')
manager = pylab.get_current_fig_manager()
values=[]
values = [0 for x in range(100)]
Ta=0.01
fa=1.0/Ta
fcos=3.5
Konstant=cos(2*pi*fcos*Ta)
T0=1.0
T1=Konstant
def SinwaveformGenerator(arg):
global values,T1,Konstant,T0
#ohmegaCos=arccos(T1)/Ta
#print "fcos=", ohmegaCos/(2*pi), "Hz"
Tnext=((Konstant*T1)*2)-T0
if len(values)%100>70:
values.append(random()*2-1)
else:
values.append(Tnext)
T0=T1
T1=Tnext
def RealtimePloter(arg):
global values
CurrentXAxis=pylab.arange(len(values)-100,len(values),1)
line1[0].set_data(CurrentXAxis,pylab.array(values[-100:]))
ax.axis([CurrentXAxis.min(),CurrentXAxis.max(),-1.5,1.5])
manager.canvas.draw()
#manager.show()
timer = fig.canvas.new_timer(interval=20)
timer.add_callback(RealtimePloter, ())
timer2 = fig.canvas.new_timer(interval=20)
timer2.add_callback(SinwaveformGenerator, ())
timer.start()
timer2.start()
pylab.show()
For a smal test, I get two different Error's. For the first one it is the following:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1519, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute __path__
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Timo/PycharmProjects/GUI_test/matplotlib.py", line 1, in <module>
from matplotlib.pyplot import plot, show
File "C:\Users\Timo\PycharmProjects\GUI_test\matplotlib.py", line 1, in <module>
from matplotlib.pyplot import plot, show
ImportError: No module named 'matplotlib.pyplot'; matplotlib is not a package
And for the second bigger example it is this:
Traceback (most recent call last):
File "C:/Users/Timo/PycharmProjects/GUI_test/matplotlib.py", line 1, in <module>
import pylab
File "C:\Python33\lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Users\Timo\PycharmProjects\GUI_test\matplotlib.py", line 4, in <module>
xAchse=pylab.arange(0,100,1)
AttributeError: 'module' object has no attribute 'arange'
Afterwards I changed the imports to the ones Pycharm wanted me to use. from matplotlib import pylab but this only resulted in an ImportError. cannot import pylab
The funny thing is, if I run these small tests in the Python Console it works just fine, so my guess is that it has something to do with PyCharm...
I also tried to add the exact path from the matplotlib to the Path variable but that resulted in another Error.
Your current project folder C:/Users/Timo/PycharmProjects/GUI_test/matplotlib.py contains matplotlib.py which causes this issue. Change the filename to anything else, which is not a name of a python package.
I have strange error, when I try to import numpy:
Traceback (most recent call last):
File "/home/timo/malltul/mafet/src/mafet/core/pattern.py", line 7, in <module>
import numpy as np
File "/usr/lib/python2.6/dist-packages/numpy/__init__.py", line 147, in <module>
import ma
File "/usr/lib/python2.6/dist-packages/numpy/ma/__init__.py", line 44, in <module>
import core
File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 4850, in <module>
all = _frommethod('all')
File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 4824, in __init__
self.__doc__ = self.getdoc()
File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 4830, in getdoc
signature = self.__name__ + get_object_signature(meth)
File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 109, in get_object_signature
import inspect
File "/usr/lib/python2.6/inspect.py", line 39, in <module>
import tokenize
File "/usr/lib/python2.6/tokenize.py", line 38, in <module>
COMMENT = N_TOKENS
NameError: name 'N_TOKENS' is not defined
It seems that the cause of the problem is that my script is in my own package named core and whenever I try to import numpy there, I get the error. Importing works fine elsewhere.
The only solution I've got this far is to rename my 'core' package to something else. Why does this matter? Am I doing something wrong?
I'm using Python2.6 on Ubuntu 10.14 . Numpy version is 1.3.0 .
EDIT: Actually renaming my package does not fix it. Renaming token.py in my package fixes it. Sorry for the error.
I doubt this has anything to do with your core module or with numpy.
From the stack trace, it would appear that the problem is with the tokenize module, which is part of Python, not part of numpy. Tokenize does from token import * and then uses N_TOKENS that's defined in token.py.
First of all, I'd check that there's no stray module called token on your PYTHONPATH:
>>> import token
>>> token.__file__
'/usr/lib/python2.6/token.pyc'
If this picks up the above file yet you still get the problem, I'd suggest reinstalling Python.