Import numpy not going good? - python

When I import numpy it sends a bunch of errors
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/.local/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/home/user/.local/lib/python2.7/site-packages/numpy/core/__init__.py", line 59, in <module>
from . import numeric
File "/home/user/.local/lib/python2.7/site-packages/numpy/core/numeric.py", line 3093, in <module>
from . import fromnumeric
File "/home/user/.local/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 17, in <module>
from . import _methods
File "/home/user/.local/lib/python2.7/site-packages/numpy/core/_methods.py", line 158, in <module>
_NDARRAY_ARRAY_FUNCTION = mu.ndarray.__array_function__
AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'

The easiest solution would be to reinstall numpy.
Open command prompt and type:
pip3 uninstall numpy
or
pip uninstall numpy
for python 2,
then,
pip install numpy

Related

AttributeError: module 'numpy.random' has no attribute 'mtrand'

After having installed the pyclustertend package with pip install pyclustertend, I now try to import it into Python:
from pyclustertent import ivat
However, I get the following error while doing so:
Traceback (most recent call last):
File "", line 1, in
from pyclustertend import ivat
File "C:\Users\Emil\AppData\Roaming\Python\Python38\site-packages\pyclustertend_init_.py", line 1, in
from .hopkins import hopkins # noqa: F401
File "C:\Users\Emil\AppData\Roaming\Python\Python38\site-packages\pyclustertend\hopkins.py", line 5, in <module>
from sklearn.neighbors import BallTree
File "C:\Users\Emil\Anaconda3\lib\site-packages\sklearn\__init__.py", line 82, in <module>
from .base import clone
File "C:\Users\Emil\Anaconda3\lib\site-packages\sklearn\base.py", line 17, in <module>
from .utils import _IS_32BIT
File "C:\Users\Emil\Anaconda3\lib\site-packages\sklearn\utils\__init__.py", line 29, in <module>
from .fixes import parse_version, threadpool_info
File "C:\Users\Emil\Anaconda3\lib\site-packages\sklearn\utils\fixes.py", line 47, in <module>
class loguniform(scipy.stats.reciprocal):
File "C:\Users\Emil\Anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 1601, in __init__
super(rv_continuous, self).__init__(seed)
File "C:\Users\Emil\Anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 588, in __init__
self._random_state = check_random_state(seed)
File "C:\Users\Emil\Anaconda3\lib\site-packages\scipy\_lib\_util.py", line 202, in check_random_state
return np.random.mtrand._rand
AttributeError: module 'numpy.random' has no attribute 'mtrand'
I suspected this has to do with the Numpy version. However, during the installation, it updated numpy to an older version:
Successfully uninstalled numpy-1.23.4
Successfully installed numpy-1.20.3 pyclustertend-1.8.2
What do I need to do to use this package?

Error "Trying to re-register the builtin cmap 'cubehelix' when trying to import the python module "yt"

I installed the Python package yt simply through pip install yt. When I tried to import it, it returns the following error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\User\Anaconda3\lib\site-packages\yt\__init__.py", line 63, in <module>
from yt.fields.api import \
File "C:\Users\User\Anaconda3\lib\site-packages\yt\fields\api.py", line 19, in <module>
from . import angular_momentum
File "C:\Users\User\Anaconda3\lib\site-packages\yt\fields\angular_momentum.py", line 26, in <module>
from .vector_operations import \
File "C:\Users\User\Anaconda3\lib\site-packages\yt\fields\vector_operations.py", line 32, in <module>
from yt.geometry.geometry_handler import \
File "C:\Users\User\Anaconda3\lib\site-packages\yt\geometry\geometry_handler.py", line 29, in <module>
from yt.utilities.parallel_tools.parallel_analysis_interface import \
File "C:\Users\User\Anaconda3\lib\site-packages\yt\utilities\parallel_tools\parallel_analysis_interface.py", line 30, in <module>
from yt.data_objects.image_array import ImageArray
File "C:\Users\User\Anaconda3\lib\site-packages\yt\data_objects\image_array.py", line 18, in <module>
from yt.visualization.image_writer import write_bitmap, write_image
File "C:\Users\User\Anaconda3\lib\site-packages\yt\visualization\image_writer.py", line 26, in <module>
from .color_maps import mcm
File "C:\Users\User\Anaconda3\lib\site-packages\yt\visualization\color_maps.py", line 164, in <module>
add_colormap("cubehelix", _cubehelix_data)
File "C:\Users\User\Anaconda3\lib\site-packages\yt\visualization\color_maps.py", line 52, in add_colormap
mcm.register_cmap(name, yt_colormaps[name])
File "C:\Users\User\Anaconda3\lib\site-packages\matplotlib\cm.py", line 149, in register_cmap
raise ValueError(msg)
ValueError: Trying to re-register the builtin cmap 'cubehelix'.
I have tried to search online for solutions but it seems that almost nobody has ever addressed the same issue. I have tried to force reinstall it by pip install --upgrade --force-reinstall yt but still the same error message occurred. How should I solve it?
I googled your error and found https://mail.python.org/archives/list/yt-users#python.org/message/5C2ZTKNETGVY24QY2G6ED33CGFUPRQSW/ from a couple of months ago, which leads to https://github.com/yt-project/yt/pull/3149.
It looks like the workaround could be to downgrade Matplotlib to a version less than 3.4.0.

ImportError: cannot import name 'Type' when importing 'gensim"

I want to import the "genism" library. I have previously successfully installed it by typing the following in the command prompt:
pip install gensim
However, the following error appears when importing it:
Traceback (most recent call last):
File "C:/Users/PycharmProjects/untitled/file.py", line 3, in <module>
import gensim
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\__init__.py", line 5, in <module>
from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\parsing\__init__.py", line 4, in <module>
from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2, # noqa:F401
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\parsing\preprocessing.py", line 42, in <module>
from gensim import utils
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\utils.py", line 40, in <module>
import scipy.sparse
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\__init__.py", line 156, in <module>
from . import fft
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\fft\__init__.py", line 76, in <module>
from ._basic import (
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\fft\_basic.py", line 1, in <module>
from scipy._lib.uarray import generate_multimethod, Dispatchable
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\_lib\uarray.py", line 27, in <module>
from ._uarray import *
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\_lib\_uarray\__init__.py", line 114, in <module>
from ._backend import *
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\_lib\_uarray\_backend.py", line 1, in <module>
from typing import (
ImportError: cannot import name 'Type'
I have also previously successfully installed the "typing" library":
pip install typing
What should I do?
It is because Python 3.5 has its own version typing, and it is incompatible with the installed version of gensim. Upgrade to python3.6 could solve the problem.

SVM import failed after installing scikit-neuralnetwork

I just installed Python's scikit-neuralnetwork using the procedure mentioned, that is;
pip install scikit-neuralnetwork
Now I can not import SVM. This line;
from sklearn import svm
gives this error;
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/__init__.py", line 13, in <module>
from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC, \
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/classes.py", line 4, in <module>
from .base import _fit_liblinear, BaseSVC, BaseLibSVM
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/base.py", line 12, in <module>
from ..multiclass import _ovr_decision_function
File "//anaconda/lib/python2.7/site-packages/sklearn/multiclass.py", line 44, in <module>
from .metrics.pairwise import euclidean_distances
File "//anaconda/lib/python2.7/site-packages/sklearn/metrics/__init__.py", line 33, in <module>
from . import cluster
File "//anaconda/lib/python2.7/site-packages/sklearn/metrics/cluster/__init__.py", line 21, in <module>
from .bicluster import consensus_score
File "//anaconda/lib/python2.7/site-packages/sklearn/metrics/cluster/bicluster/__init__.py", line 1, in <module>
from .bicluster_metrics import consensus_score
File "//anaconda/lib/python2.7/site-packages/sklearn/metrics/cluster/bicluster/bicluster_metrics.py", line 6, in <module>
from sklearn.utils.validation import check_arrays
ImportError: cannot import name check_arrays
May I know what went wrong? I'll try using different environments next time, if that helps. Is there any way to fix this?
I am using Python 2.7 and sklearn 0.17.
open sklearn.utils.validation and delete "import check_arrays", or use other package for example anaconda3. i check now - no problems. Or install anaconda3.5 and copy check_arrays to anaconda2.7 sklearn.utils.validation.

Install Error Pygame

I have Ubuntu 12.04 with Python 2.7 and Python 3 installed. I installed pygame through sudo apt-get python-pygame and also from the source. When I tried >>>import pygame on Python I get this error:
`
>>> import pygame<br>
Jello, world!<br>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pygame/__init__.py", line 255, in <module>
try: import pygame.surfarray
File "/usr/lib/python2.7/dist-packages/pygame/surfarray.py", line 69, in <module>
import pygame._numpysurfarray as numpysf
File "/usr/lib/python2.7/dist-packages/pygame/_numpysurfarray.py", line 48, in <module>
import numpy
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
import polynomial
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/__init__.py", line 18, in <module>
from polynomial import Polynomial
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/polynomial.py", line 60, in <module>
from polytemplate import polytemplate
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/polytemplate.py", line 20, in <module>
polytemplate = string.Template('''
AttributeError: 'module' object has no attribute 'Template'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 66, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 1, in <module>
from apport.report import Report
File "/usr/lib/python2.7/dist-packages/apport/report.py", line 18, in <module>
import problem_report
File "/usr/lib/python2.7/dist-packages/problem_report.py", line 16, in <module>
from email.mime.multipart import MIMEMultipart
File "/usr/lib/python2.7/email/mime/multipart.py", line 9, in <module>
from email.mime.base import MIMEBase
File "/usr/lib/python2.7/email/mime/base.py", line 9, in <module>
from email import message
File "/usr/lib/python2.7/email/message.py", line 16, in <module>
import email.charset
File "/usr/lib/python2.7/email/charset.py", line 14, in <module>
import email.quoprimime
File "/usr/lib/python2.7/email/quoprimime.py", line 48, in <module>
from string import hexdigits
ImportError: cannot import name hexdigits
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pygame/__init__.py", line 255, in <module>
try: import pygame.surfarray
File "/usr/lib/python2.7/dist-packages/pygame/surfarray.py", line 69, in <module>
import pygame._numpysurfarray as numpysf
File "/usr/lib/python2.7/dist-packages/pygame/_numpysurfarray.py", line 48, in <module>
import numpy
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
import polynomial
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/__init__.py", line 18, in <module>
from polynomial import Polynomial
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/polynomial.py", line 60, in <module>
from polytemplate import polytemplate
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/polytemplate.py", line 20, in <module>
polytemplate = string.Template('''
AttributeError: 'module' object has no attribute 'Template'
I saw the Jello World so I guess it is working a bit. I dont know what to do. I appreciate the help. Thanks in advance.
That looks like you don't have SDL installed on your box.
Remove your current pygame packages then dot he following:
wget http://www.libsdl.org/release/SDL-1.2.14.tar.gz
tar -xzvf SDL-1.2.14.tar.gz
cd SDL-1.2.14
./configure
make
make install
Once this has completed reinstall pygame but try reinstalling via easy_install or pip:
easy_install pygame
or
pip install pygame
You should be good to go after that.

Categories

Resources