I get `No module named _multiarray_umath` when using matplotlib - python

When I run my tests in CI, I get the following error:
ImportError while importing test module '/home/tests/test_process.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
...
.tox/py27/lib/python2.7/site-packages/matplotlib/pyplot.py:31: in <module>
import matplotlib.colorbar
.tox/py27/lib/python2.7/site-packages/matplotlib/colorbar.py:36: in <module>
import matplotlib.contour as contour
.tox/py27/lib/python2.7/site-packages/matplotlib/contour.py:14: in <module>
import matplotlib._contour as _contour
E ImportError: numpy.core.multiarray failed to import
----- Captured stderr -----
ImportError: No module named _multiarray_umath
What's going on here? I haven't made any changes to my code, but all the sudden
my build started failing.

Solution
Install numpy using pip seperately, before installing your sdist.
For tox, add numpy directly to your deps array.
Why did this happen?
Numpy recently published numpy-1.16.0rc2 to pypy, which is what (in conjunction with a bug/oversight in easy_install) broke your build:
pip knows not to install RCs by default, but easy_install (which matplotlib uses to do their builds) does not. If you were to do sdist with a whole bunch of -vvvvvvs, you'd see something like this:
gcc ... -I/tmp/pip-install-Eh8d9d/matplotlib/.eggs/numpy-1.16.0rc2-py2.7-linux-x86_64.egg/numpy/core/include ... -o build/temp.linux-x86_64-2.7/src/_contour.o
In particular, note that matplotlib is being built against numpy-1.16.0rc2-py2.7. But then in another place you might see something like
Successfully installed ... numpy-1.15.4 ...
So then when you try and run your program, matplotlib will try to access modules that don't exist in the non-RC version of numpy, and fail.
If you already have numpy installed, easy_install won't try and fetch its own version, and will instead use the (correct) existing version.
See also
http://numpy-discussion.10968.n7.nabble.com/Issue-with-setup-requires-and-1-16-release-candidates-td46600.html

The solution is that you need to upgrade numpy.
If you are using pip
pip install numpy --upgrade
Hope it helps.

Related

Unable to Install numpy. No module named 'numpy.core._multiarray_umath'

This is the complete error message I received:
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.10 from "D:\hugging-face\nlp\Scripts\python.exe"
* The NumPy version is: "1.21.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
I checked my Python version by typing python -v it the output was 3.10.5 is that alright?
I tried checking the NumPy version by typing:
import numpy
numpy.version
However, it gave me the same error about numpy.core.multiarray_umatch`. So, I tried to install numpy by running the following command:
pip install numpy
It gave me the following error:
ImportError: cannot import name 'Mapping' from 'collections' (D:\python\lib\collections\__init__.py)
I would also like to add that there are two directories inside lib with names numpy and numpy-1.21.5.dist-info. So, I guess the library is already installed but I can;t use it for some reason.
The contents of my pyvenv.cgf file are:
home = D:\python
include-system-site-packages = false
version = 3.7.4
What should I do?
This may work, just give it a try
as you are using python 3.10 you need to install numpy version greater than 1.21.5
create new environment
cd <path where you need your virtualenv>
python -m venv .venv
as you are using windows activate using virtual env
.venv\Scripts\activate assuming your are already in the virtualenv folder
then try pip install numpy>=1.23

Module Not Found Error after library installation

I am trying to use the Scratch library.
For example:
from scratch.probability import normal_cdf
from scratch.linear_algebra import Vector, dot
#...
I installed Scratch using pip install scratch but I receive this error: ModuleNotFoundError: No module named 'scratch'.
Can you help me?
pip install scratch will install this: https://pypi.org/project/scratch/
But I guess that what you want to use is that: https://github.com/joelgrus/data-science-from-scratch
The second one is not meant to be installed through pip but used directly in a clone of the project as documented in its README.
About pip install scratch-probability (https://pypi.org/project/scratch-probability/#description), as it's not documented, you need to go check the content of the tarball to know how the package inside are named (if they are what's expected).

Numpy Import Error in Anaconda Environment using Spyder (WINDOWS)

BACKGROUND
Just two days ago I was able to run any program that had a numpy dependency. Now when I try to run my code using pandas, matplotlib or any module that depends on numpy, I get the below error:
Traceback (most recent call last):
File "<ipython-input-8-8fcf286af663>", line 7, in <module>
import numpy
File "path\to\Python\Python38\site-packages\numpy\__init__.py", line 140, in <module>
from . import core
File "path\to\Python\Python38\site-packages\numpy\core\__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.7 from "C:\ProgramData\Anaconda3\pythonw.exe"
* The NumPy version is: "1.19.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
SETTINGS CHECK
The return message references this site: https://numpy.org/devdocs/user/troubleshooting-importerror.html but nothing there has helped me.
I checked my Path variable to make sure that all the required directory locations are there and there is no issue.
I successfully import numpy when I compile code from cmd using python -c "import numpy; print('done')"
I am using an anaconda environment, the Spyder IDE, and again it was just fine two days ago.
I checked the python version from pythonw.exe and it seems fine as well
What could be wrong with my environment?
ATTEMPTED SOLUTIONS HERE
Also, I've checked the following links with no success:
Importing the numpy c-extensions failed
importing numpy package in Spyder, Python
python Spyder not importing numpy
https://github.com/numpy/numpy/issues/15090
Can't import numpy anaconda
Import error: Anaconda numpy (numpy and Anaconda already installed, virtualenv)
Turns out my problem was very simple. The main solution I was trying was to uninstall and reinstall.
Every time I installed and uninstalled the modules, I did so from the standard command line.
That was wrong since anaconda uses its own virtual environment to store data.
So all I had to do was run this command from the anaconda command prompt:
pip install --upgrade pandas && pip install --upgrade numpy
this command would work just as well:
pip uninstall pandas && pip uninstall numpy && pip install pandas
(since the last install would automatically download any dependencies that pandas has, which is numpy

Failed to install scitools-iris using pip: ImportError No module named target_pkg (in pyke)

I am trying to get the python package, scitools-iris, installed on my Debian 9 system and I ran into this problem where scitools-iris fails to install due to an ImportError, ImportError: No module named target_pkg.
I am using python 2.7 and all packages are installed using pip only. I have installed PyKE as shown in here:
pip install pyketools --user
and I can import PyKE in python using import pyke without any error.
Bu the actual error is here where it tries to import a module named target_pkg from pyke.target_pkg. I tried the import statement in python,
from pyke.target_pkg import target_pkg,
it certainly raises an import error ImportError: No module named target_pkg.
How do I get around this problem and install iris in my system?
Have I installed the wrong package for PyKE?
Found out what I have been doing wrong. I actually had the wrong package installed for PyKE using pip. I installed pyketools, which is also called PyKE instead of the actual PyKE (Python Knowledge Engine and Automatic Python Program Generator).
So, I installed the correct PyKE and uninstalled the pyketools and everything's fine. Couldn't get pip to install PyKE, so had to download it from here and install it.

ImportError: No module named naive_bayes

I just installed sklearn, my program runs no problem when I import it into the code. However, whenever I try to access the naive_bayes module, I get this error:
ImportError: No module named naive_bayes
Here's how I'm importing it:
from sklearn.naive_bayes import GaussianNB
Not sure where I'm going wrong, any help is much appreciated!
In the spirit of "turn it off, and turn it back on again" solutions, and given the fact that you're getting a Module has no attribute: __version__ when you try and print the scikit-learn version (which should be defined in any self-respecting Python module), I'm going to recommend you uninstall and reinstall scikit-learn:
pip uninstall sklearn
pip install sklearn
Run the following commands, and compare to the output provided, to make sure the package is behaving the way it should:
>>> import sklearn
>>> print(sklearn.__version__)
0.19.0
>>> print(sklearn.__file__)
/usr/local/lib/python3.6/site-packages/sklearn/__init__.py
>>>
The output from printing sklearn.__file__ does not need to match exactly, but it should at least print some location on your computer.
Also, check to make sure your pip matches your python. This depends on what platform you're on, but this mix of version 2 and version 3 sometimes creates a nasty cocktail. Executing pip --version should tell you which version of Python it is tied to.
$ which pip3
/usr/local/bin/pip3
$ pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
$ which python3
/usr/local/bin/python3
You should be OK with Python version 2, so long as things match.
(Soap box moment: move to Python 3 if you don't have a really good reason for sticking with Python 2!)
It seems that the sklearn installation does not include the naive_bayes in your installation. If the sklearn install correctly, it would say something like
ImportError: No module named 'sklearn.naive_bayes2'
However, in your case, the import error shows a bit different output. Please check the version and run the test file.
I had the same problem while installing sklearn and scikit-learn through pip.
I fixed the issue through the following steps
pip uninstall sklearn (if already installed)
pip uninstall scikit-learn( if already installed)
git clone scikit-learn
cd scikit-learn
python setup.py install
Hope this will help you.

Categories