AttributeError: 'numpy.ufunc' object has no attribute '__module__' - python-2.7

I have installed skimage using 'pip install scikit-image' inside a conda environment.
I am using python 2.7.
When I try importing :
from skimage import transform
It gives me the error:
AttributeError: 'numpy.ufunc' object has no attribute 'module'
Can someone please help me out?

Seems like you have mismatched version of scikit-image and numpy because of the recent updates in each of it's respective library. The correct version that I found works compatible with each other is 0.14.1 for scikit-image and 1.15.4 for numpy.
Install these specific version of libraries by executing these commands:
pip uninstall scikit-image
pip uninstall numpy
pip install scikit-image==0.14.1
pip install numpy==1.15.4
Now importing these libraries should work and produce no error.

Related

Installing NumPy + SciPy in Python 2.7 now fails with "RuntimeError: Python version >= 3.5 required"

Installing numpy and scipy from source like this (say, in a fresh Python 2.7 pyenv virtualenv):
pip install numpy==1.14.6 scipy==1.0.1 --no-binary numpy,scipy
gets their installers to use a ~/.numpy-site.cfg file that points to my openblas installation.
This used to work. Now it produces a long stack trace ending with:
File "/usr/local/var/pyenv/versions/2.7.16/envs/issue/lib/python2.7/site-packages/setuptools/sandbox.py", line 45, in _execfile
exec(code, globals, locals)
File "/var/folders/_b/q30qg_l50b5gvqd8y4_wb9h00000gn/T/easy_install-o9MJ5E/numpy-1.17.1/setup.py", line 31, in <module>
if sys.version_info[0] < 3:
RuntimeError: Python version >= 3.5 required.
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Q. What changed?
Q. Why does it say Python version >= 3.5 required. in a Python 2.7 installation?
Q. How to fix it?
The scipy 1.0.1 installer requires numpy as a prerequisite, but the multiple installers working together end up getting the latest version of numpy unless numpy is already present.
What changed: The latest version of numpy requires Python 3.5+, hence the error message.
So even though the pip command explicitly asked to install numpy==1.14.6 scipy==1.0.1, it triggers a newer numpy installer that fails on Python 2. (The last entry in the stack trace shows numpy-1.17.1 requiring Python 3.)
The problem arises in the interaction between pip, the scipy and numpy installers, and easy_install. Details in pip issue #6945.
Workaround: Install numpy first. Then install scipy. Alternatively, the one-line install might work if you don't need the --no-binary option.
I also encountered an issue where scipy was been installed through a script and it was trying to install a version 1.7.1 which required python 3.7 at least and i hand 3.6. The workaround was i installed scipy myself and the version i got was 1.5.4.

Issues installing OpenCV 3.2.0 (Windows)

So I was trying to follow the steps from the link below
http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html#install-opencv-python-in-windows
Below Python packages are to be downloaded and installed to their default locations.
1.1. Python-2.7.x.
1.2. Numpy.
1.3. Matplotlib (Matplotlib is optional, but recommended since we use it a lot in our tutorials).
Install all packages into their default locations. Python will be installed to C:/Python27/.
After installation, open Python IDLE. Enter import numpy and make sure Numpy is working fine.
Download latest OpenCV release from sourceforge site and double-click to extract it.
Goto opencv/build/python/2.7 folder.
Copy cv2.pyd to C:/Python27/lib/site-packages.
Open Python IDLE and type following codes in Python terminal.
import cv2
print cv2.version
If the results are printed out without any errors, congratulations !!! You have installed OpenCV-Python successfully.
When I try to type "import cv2" I get this error:
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x7
Traceback (most recent call last):
File "", line 1, in
import cv2
ImportError: numpy.core.multiarray failed to import
What could this be?
I ended up solving my own problem using pip-installer. The link is at the bottom. What ended up happening was I was trying to install Numpy 1.8, when I should have let pip-installer "update" to the actual correct version necessary.
https://github.com/BurntSushi/nfldb/wiki/Python-&-pip-Windows-installation
along with the command I used:
pip install --upgrade numpy
This will allow for the correct version of Numpy to be installed.
Read the error information carefully, the opencv base on version 0xa compiled, but the found numpy version is 0x7.
When I try to type "import cv2" I get this error: RuntimeError: module compiled against API version 0xa but this version of numpy is 0x7
You may need upgrade the numpy module to the latest version.
pip install numpy --upgrade
it worked for me too.Thanks..just giving further illustaration.
my numpy was on 1.7.1 and it was giving error while doing import cv2.
I downloaded/copied the pip data from the above mentioned link, renamed as get-pip.py in the Scripts folder under Python27. Once done, I ran python get-pip.py command(u need to set the env variable for Python so that it can be executed from under Script folder where the get-pip.py file is kept) through the windows command terminal. This installad the pip to my system.
After then in the cmd terminal, went to Scripts folder and ran the cmd pip install --upgrade numpy which then Successfully installed numpy-1.13.1.
It was giving some problem due to previous numpy version, which i uninstalled through the control panel.
Cheers,

not able to upgrade matplotlib to 1.4.3 on ubuntu 14.04

I've tried upgrading matplotlib using the following commands:
$export PYTHONHOME=/usr/lib/python2.7/
$sudo easy_install -U distribute
$sudo pip install --upgrade matplotlib
But none of them have worked. It shows an error after the matplotlib 1.4.3 package is downloaded but not installed.
Can anyone help upgrading this correctly?
The error you get says this.
============================================================================
* The following required packages can not be built:
* freetype, png
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/matplotlib
Storing debug log for failure in /home/snapey/.pip/pip.log
If you look further up, it says
REQUIRED DEPENDENCIES AND EXTENSIONS:
... <Some other packages, all present>
freetype: no [The C/C++ header for freetype2 (ft2build.h)
could not be found. You may need to install the
development package.]
png: no [pkg-config information for 'libpng' could not
be found.]
So, it's telling you the problem - freetype and png are not present and cannot be built
To rectify this - install them like so:
sudo apt-get install libfreetype6-dev libpng12-dev
This is almost a duplicate question, but looks like the problem is Python 3 specific (it isn't).
I found I then had to run pip install --upgrade matplotlib twice, as it failed with an error about python.h first time, but then I had matplotlib 1.4.3. Tested on Ubuntu 14.04 64 bit, python 2.7
As an aside - this is really ugly and should probably be raised with Ubuntu and / or matplotlib devs.

ImportError when importing certain modules from SciPY

I have used Scipy for some time. This is the first time I am using it for Signal processing!
But when I import modules like
from scipy import signal
from scipy import special
I get the error:
ImportError: DLL load failed: The specified module could not be found.
I am using Python 2.7.3 with Scipy 0.12.0 on 32-Bit Windows.
What should I do ?
This problem can be solved if instead of installing the usual numpy distribution, the numpy-MKL package is installed.
This package is available here.
Do remove the previous installation before going with the new one!
I already had numpy+mkl installed, but still I faced similar error.
Reinstalling has solved the issue:
pip uninstall numpy-1.13.1+mkl-cp35-cp35m-win_amd64.whl
pip install numpy-1.13.1+mkl-cp35-cp35m-win_amd64.whl
I installed numpy-MKL from here for Python 3.5.1, but it didn't solve the problem until I added the folder C:\Program Files\Python35\Lib\site-packages\numpy\core to system path.
Similar to the OP, I already had the Intel MKL libraries installed on my system. I was unable to load scipy.linalg with the same error message. I uninstalled the old version of numpy and scipy (which I installed before installing the Intel compilers and math libraries). Then ran pip install scipy, and magically I could now import scipy.linalg without the error.
I'm not entirely sure what caused it, and why it was unable to find the library it needed. But it somehow fixed the problem for me on Python 3.7.1 with Anaconda.
I had an issue importing sklearn because of my Scipy installation.
I fixed this by going to here and downloading the right version of numpy for my computer. Then I did the same for Scipy by going here and downloading the MKL version for my computer.
Once I did that, everything worked!
To check the supported tags for wheel version for your system you can run the following command in the command prompt: pip debug --verbose.
You can install the .whl files for numpy and scipy by doing: pip install {filename}.whl
I had this issue on 3.6 and reinstalling didn't work,downloading the wheel didn't work. I found a solution that did work:
go to "site-packages/scipy" folder and open __init__.py file for editting.
At the very bottom add this line of code:
from . import signal
from . import special
from . import linalg
from . import <insert missing submodule here>
this is the only solution that has worked for me and it should work for any one

Trouble getting Virtualenv to Import Numpy

I am having trouble with all libraries, but let me focus on numpy. If I am outside a virtualenv, I can go into the Python interpreter and do:
import numpy
and that works. But if I got into a virtualenv and try it:
$ workon test
(test):~/Project/test$ python
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
After hours of Googling I believe the problem must be in my understanding of virtualenv and virtualenvwrapper. I have tried the obvious:
(test):~/Projects/test$ pip install numpy
but I got the error:
SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
I also tried doing sudo apt-get install python-dev but got the errors:
The following packages have unmet dependencies:
python-dev : Depends: python2.7-dev (>= 2.7.3) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
I am running Python2.7.3 on Ubuntu 12.04 and have PyDev (no virtualenv) running with a project that currently imports libraries (like numpy) with no trouble. I have tried using the Ubuntu Software Center to install python-dev, but I get the same errors.
virtualenv by default doesn't let you import packages from the global environment. Use [mk]virtualenv --system-site-packages to allow it to import system packages.
python-dev is a system package, so the pip error is expected. Not sure about the apt error, but you could ask on askubuntu.com to try to resolve it.