ImportError: No module named 'numpy.ma' - python

The full error:
import matplotlib
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import matplotlib
File "R:\Python34\lib\site-packages\matplotlib\__init__.py", line 180, in <module>
from matplotlib.cbook import is_string_like
File "R:\Python34\lib\site-packages\matplotlib\cbook.py", line 34, in <module>
import numpy.ma as ma
ImportError: No module named 'numpy.ma'
numpy is imported normally.
How do I install numpy.ma?

I also faced the same situation today. I found that I had saved a file as numpy.py, so check the filenames in your folder.

Re-install the correct version of numpy.
download correct .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
pip install C:\Path\To\Wheel\Filename.whl # for example: numpy-1.9.2+mkl-cp34-none-win_amd64.whl

Use Your (via terminal) package manager and search.
Example on Ubuntu:
aptitude search numpy
and install package.
In my case:
apt-get install python-numpy

Related

Python modulenotfound error - Is there a "pip" alternative way to install python modules

I am trying to run a program (obviously written in python) and it requires some python modules. One of the missed modules is aiomultiprocess. I tried installing it with pip install aiomultiprocess pip3 install aiomultiprocess python3.7 -m pip install aiomultiprocess but they all come back with the same error message:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 19, in <module>
from setuptools.dist import Distribution
File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 34, in <module>
from setuptools import windows_support
File "/usr/local/lib/python3.7/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/local/lib/python3.7/ctypes/__init__.py", line 10, in <module>
from _ctypes import Union, Structure, Array
File "/usr/local/lib/python3.7/_ctypes.py", line 5, in <module>
import ffi
ModuleNotFoundError: No module named 'ffi'
No ffi module?! Let's get it!
I looked it up and figured it's a foreign library that come, in the case of python, as 2 forms: CFFI & LibFFI, but "ffi" doesn't exist for python. I installed cffi libffi and added them to this path /usr/local/lib/python3.7/site-packages/, but it changed nothing.
So my question is there another way to install python modules without the need of pip??!

ImportError: cannot import name 'registry' from 'pandas.core.dtypes.base'

I just did a conda install of a few packages to follow a tutorial, and now I can't even import pandas.
I installed these:
fake-factory==0.7.2
Faker==0.7.3
pytz==2016.7
tzlocal==1.3.0
And now I get this:
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\__init__.py", line 42, in <module>
from pandas.core.api import *
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\api.py", line 7, in <module>
from pandas.core.arrays.integer import (
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\arrays\__init__.py", line 2, in <module>
from .base import (ExtensionArray, # noqa
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\arrays\base.py", line 21, in <module>
from pandas.core import ops
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\ops\__init__.py", line 21, in <module>
from pandas.core.construction import extract_array
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\construction.py", line 18, in <module>
from pandas.core.dtypes.base import ExtensionDtype, registry
ImportError: cannot import name 'registry' from 'pandas.core.dtypes.base' (C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\dtypes\base.py)
I tried doing a conda update pandas, but to no avail.
I also just installed luigi, not quite sure when it broke as I installed all the additional packages in one go.
Updated version of pandas package using pip3
try this in python3
pip3 install --upgrade pandas
Try updating pandas package in Anaconda:
conda install pandas=1.1.4
If no luck, try updating all packages:
conda update --all
Worked in my case.

Anaconda Python - how to reinstall NumPy

I am using Anaconda 5.3.0's Python interpreter in Visual Studio Code. When I try to import sklearn I get an error:
Traceback (most recent call last):
File "c:\Users\azzam\machinelearning.py", line 1, in <module>
import sklearn
File "C:\Anaconda3\lib\site-packages\sklearn\__init__.py", line 134, in <module>
from .base import clone
File "C:\Anaconda3\lib\site-packages\sklearn\base.py", line 10, in <module>
import numpy as np
File "C:\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: The specified module could not be found.
It looks like that I need to "reinstall" NumPy. I searched on the web, but I didn't find a way to "reinstall". There is only how to "install", and when I use
conda install numpy
in Anaconda Prompt I get:
Solving environment: done
# All requested packages already installed.
And if I tried to remove NumPy to install it again, it will remove everything, not just NumPy. So do I really need to "reinstall" NumPy to be able to import sklearn?
And if I do, how do I "reinstall" NumPy?
How to reinstall a package depends on the conda version.
newer versions (>= 4.6):
conda install numpy --force-reinstall
older versions (< 4.6):
conda install numpy --force
You will most likely have to uninstall NumPy and reinstall it.
conda remove numpy
And then install it again:
conda install -c anaconda numpy

Installing Matplotlib in Windows 10 64bits

Could anyone tell me what files I should download and which statements I must execute in the command line to install Matplotlib?
I have Python 2.7.13 on Windows 10 64 bit.
These are the files I unzipped:
All downloaded from: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Commands I executed:
python -m pip install -U pip setuptools
python -m pip install matplotlib
python -m pip install -U pip
I am getting these two errors when checking if Numpy and Matplotlib are installed.
>>> import numpy
**Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import numpy
File "numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: %1 no es una aplicación Win32 válida.**
>>> import matplotlib
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import matplotlib
File "matplotlib\__init__.py", line 122, in <module>
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
File "matplotlib\cbook.py", line 33, in <module>
import numpy as np
File "numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: %1 no es una aplicación Win32 válida.
This is a common issue for windows users. And you will probably need precompiled packages for some other libraries as well, e.g. scipy.
You will find on SourceForge the numpy superpack whose name structure is numpy-X.X.X-win32-superpack-python2.7.exe, e.g. numpy-1.9.2-win32-superpack-python2.7.
On Pypi (Python Package Index), you will find the matplotlib library, whose name structure is matplotlib-X.X.X.win32-py2.7.exe, e.g matplotlib-1.4.3.win32-py2.7.exe.
Installing matplotlib through pip by automatically downloading the files from the python index as you're trying to do here will most probably fail for windows.
There are two main options:
Install a complete distribution like Anaconda, Canopy, WinPython, etc. which already has all the respective libraries included.
Use precompiled wheels. A source for those is indeed this site by Christoph Gohlke. You would then need to make sure to install all dependencies first and matplotlib last. Starting with numpy is the best, then other dependencies, matplotlib last. To install those use
pip install <filename of wheel>
e.g.
pip install numpy‑1.13.0rc1+mkl‑cp27‑cp27m‑win_amd64.whl

Python 3.5 (32-bit): ImportError: cannot import name NUMPY_MKL

I am new to Python and I am trying to install numpy+mkl and scipy (in the same order), but I get below error when I execute following steps:
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
I am using Python 3.5 (32-bit) on a Windows 7 64-bit OS.
There is a similar question already answered for the exact problem here: ImportError: cannot import name NUMPY_MKL
Going through the answer, I reinstalled my numpy+mkl pkg numpy‑1.11.2+mkl‑cp35‑cp35m‑win32.whl from the mentioned link (http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy) and then reinstalled scipy-0.18.1-cp35-cp35m-win32.whl as well, but that does not solve the problem and I still get the same error:
>>> exec(open("C:\\PythonFiles\\testpy1.py").read())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 3, in <module>
File "C:\Users\msoudagar\AppData\Local\Programs\Python\Python3532\lib\site-packages\sklearn\__init__.py", line 57, in <module>
from .base import clone
File "C:\Users\msoudagar\AppData\Local\Programs\Python\Python35-32\lib\site-packages\sklearn\base.py", line 10, in <module>
from scipy import sparse
File "C:\Users\msoudagar\AppData\Local\Programs\Python\Python3532\lib\site-packages\scipy\__init__.py", line 61, in <module>
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
ImportError: cannot import name 'NUMPY_MKL'
Any inputs would be really helpful!
Try commenting out the line
from numpy._distributor_init import NUMPY_MKL
it might just work regardless.
ImportError: cannot import name NUMPY_MKL
I know this is not the most sophisticated of solutions but, all I had to do was close the IDE(in my case, Pycharm) and re-open it again.
Not sophisticated but effective in my case :).
Check this answer. Solved my problem.
https://stackoverflow.com/a/37294205/2708266
Suggesting to download ready made binary setup from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
pip install xx.whl
I ran into the same issue on Windows with Python 3.5 64 bit. Manually installing numpy+mkl from wheel file solved the issue for me.
Select the appropriate wheel file from here (cp35,win32 for you): and install it using pip install --user Path_to_local_file.whl replacing Path_to_local_file with wherever you saved the .whl file
This is a also a duplicate of ImportError: cannot import name NUMPY_MKL

Categories