error importing numpy - numpy

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.

Related

cannot import name 'int' from 'numpy'

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.

How to solve **TypeError : expected str, bytes or os.PathLike object, not WindowsPath** when importing matplotlib to python

I am trying use matplotlib within Autodesk Revit software from the PyRevit Project
In this project, Pyrevit brings an embedded CPython interpreter (3.8.5) to Revit.
Until now, I've managed to import some packages (e.g. numpy, pandas), but unfortunately import matplotlib has been a big challenge.
When I try to import matplotlib, I got the following error:
CPython Traceback:
TypeError : expected str, bytes or os.PathLike object, not WindowsPath
File "C:\Users\carlo\pyproj\bimenv\Lib\site-packages\matplotlib\__init__.py", line 886, in <module>
rcParamsDefault = _rc_params_in_file(
File "C:\Users\carlo\pyproj\bimenv\Lib\site-packages\matplotlib\__init__.py", line 789, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
File "contextlib.py", line 113, in __enter__
File "C:\Users\carlo\pyproj\bimenv\Lib\site-packages\matplotlib\__init__.py", line 765, in _open_file_or_url
fname = os.path.expanduser(fname)
File "ntpath.py", line 293, in expanduser
...\matplotlib_init_.py
File ntpath.py
Doing the same, import matplotlib, from the Python 3.8.5 in the command line it works without any problem.
enter image description here
Thank you in advance for any suggestion from your side to solve this issue.

Is there another library I have missed before running chatterbot?

I've tried to create a chatbot program using the chatterbot library. It produced some errors which beat all attempts to resolve. Finally, I went to the chatterbot documentation online and copy/pasted the first example chatterbot code and run it in my editor. This produced the same errors. So I want to know if there is some library I have missed perhaps, what that library is and the version of the library to install?
I've run the example code from https://chatterbot.readthedocs.io/en/stable/examples.html Simple Example (as found below). It has produced the same errors.
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
# Create a new chat bot named Charlie
chatbot = ChatBot('Charlie')
trainer = ListTrainer(chatbot)
trainer.train([
"Hi, can I help you?",
"Sure, I'd like to book a flight to Iceland.",
"Your flight has been booked."
])
# Get a response to the input text 'I would like to book a flight.'
response = chatbot.get_response('I would like to book a flight.')
print(response)
I expect to have a prompt at the terminal that allows input and produces a response. I got a list of error instead.
Traceback (most recent call last):
File "/Users/ikwame.amofa/PycharmProjects/trychat/main.py", line 3, in <module>
from chatterbot import ChatBot
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/__init__.py", line 4, in <module>
from .chatterbot import ChatBot
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/chatterbot.py", line 2, in <module>
from chatterbot.storage import StorageAdapter
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/storage/__init__.py", line 1, in <module>
from chatterbot.storage.storage_adapter import StorageAdapter
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/storage/storage_adapter.py", line 3, in <module>
from chatterbot.tagging import PosHypernymTagger
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/tagging.py", line 4, in <module>
from chatterbot.tokenizers import get_sentence_tokenizer
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/tokenizers.py", line 4, in <module>
from chatterbot.corpus import load_corpus, list_corpus_files
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/corpus.py", line 5, in <module>
from chatterbot_corpus.corpus import DATA_DIRECTORY
ModuleNotFoundError: No module named 'chatterbot_corpus'
First of all, put your error message in a code tag,
Secondly, you forgot to install the library. Install it using:
pip install chatterbot-coprus

importing pandas, numpy 'module' object has no attribute 'Integral'

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.

ImportError: No module named 'matplotlib.pyplot'; matplotlib is not a package

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.