Python 3.6 and Intel numpy issue - python

I wanted to test the Intel distribution of numpy (see https://software.intel.com/en-us/articles/installing-the-intel-distribution-for-python-and-intel-performance-libraries-with-pip-and).
I followed the simple installing procedure: pip install intel-numpy
The package was installed correctly. However, the simple "import numpy as np" raised the following error:
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.
I am using Python 3.6.5 and my system is MacOs, but I got the very same error on Windows.
Does anyone know if Intel page is deprecated? Or if Intel packages are not compatible with Python 3.6.5?
PS: I know that Anaconda distribution install Intel distribution, by do I really need to use Anaconda?

Related

Importing the numpy C-extensions fails when importing a package that depends on numpy

When I import a package I built that depends on numpy (via pandas), the numpy import fails with the message below. VS Code is not in the picture.
I'm running macOS Monterey (12.3.1) on a MacBook Pro with an M1 chip.
I installed Python 3.10 from binary.
I'm using virtualenv and VS Code for development, but the failure also occurs when I run a script from Terminal.
I built a package (PyTables) that uses pandas and numpy: PyTables. It runs just fine in that project on my machine.
However, when install that built package in another project -- pip install -i https://test.pypi.org/simple/ pytables -- and then import it -- import pytables as tp -- I get the numpy import error below.
I've isolated the problem to just that import statement.
I installed pandas 1.4.1 and numpy 1.22.1 in this virtualenv using pip3, just as I did in the env where I built the package.
I also have Python 3.9.1 on my system. I need 3.10 for PySimpleGUI.
If I simply comment out the import, the code runs fine.
Import error:
ImportError: Unable to import required dependencies: numpy:
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
"/Users/alecramsay/.virtualenvs/tstudio/bin/python" * The NumPy
version is: "1.22.1"
and make sure that they are the versions you expect. Please carefully
study the documentation linked above for further help.
Original error was:
dlopen(/Users/alecramsay/.virtualenvs/tstudio/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so, 0x0002): tried:
'/Users/alecramsay/.virtualenvs/tstudio/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need
'x86_64'))

How to install scipy module installation?

I'm trying to install scipy 0.19 for python 3.6 windows 10 32 bit version. I tried the pip installation method but it doesn't work then i also downloaded the .whl file for scipy then also the program shows that "no module named scipy". How do I solve this problem?

ImportError SciKit-learn

I am trying to get started with machine learning, so I have installed the packages: numpy, Scikit-learn, matplotlib, scipy. Some I have installed directly from pip with:
python -m pip install "package name"
and and others i have downloaded the binary files and then installed with pip. It shows no errors when I import matplotlib, numpy and sklearn, but when I write:
from sklearn import svm
it gives me the error:
ImportError: cannot import name 'svm'
I am on Python 3.5.1 and on Windows 10. Does anyone have any solutions?
import sklearn.svm as svm
model = svm.SVC()
....
http://scikit-learn.org/stable/modules/classes.html#module-sklearn.svm
It does seem that you didn't install it properly. Since you're on windows I would recommend using the Unofficial Windows Binaries for Python Extension Packages website to install future packages.
Make sure you also install the proper binaries as I pointed out in this post Installing scipy in Python 3.5 on 32-bit Windows 7 Machine. The windows version doesn't matter just make sure you're downloading Visual C++ 2015 redistributable package.

Installing MayaVi on Windows, working with Python 2.7

I am trying to install the MayaVi package using pip, but I keep getting an error message saying (ImportError: No module named vtk). How do I fix this problem?
So on command prompt:
$pip install mayavi
output
File "Tvtk\code_gen.py", line 10, in
import vtk
ImportError: No module named vtk
This has actually gotten a lot easier with the new wheel format and installation.
Make sure your python setup is wheel compatible (e.g. upgrade pip and 'pip install wheel') - you may need to google around for how to do that for certain distributions like Canopy.
Then just grab either the VTK and MAYAVI wheels or the MAYAVI+VTK wheel from the inestimable http://www.lfd.uci.edu/~gohlke/pythonlibs/#vtk
Right now for example you might choose: mayavi‑4.4.0+vtk610‑cp27‑none‑win32.whl
(assuming 32 bit install of cpython 2.7, the filenames encode important stuff and there are many options)
Then run pip install mayavi‑4.4.0+vtk610‑cp27‑none‑win32.whl
I just had the occasion to do this on a laptop that I hadn't set up with Mayavi yet and it ran smooth as silk and installed everything I needed without complaint. That was several steps smoother than the last time I had to install Mayavi on a windows machine.
From my recent experience, one possible reason is that vtk for windows is not installed prior to using mayavi.
however you can't do pip install vtk.
you can get vtk from here
also, remember to configure VC Express 2008 and Windows 7 SDK + .NET 3.5 to avoid additional errors.

ValueError: numpy.dtype has the wrong size, try recompiling

I just installed pandas and statsmodels package on my python 2.7
When I tried "import pandas as pd", this error message comes out.
Can anyone help? Thanks!!!
numpy.dtype has the wrong size, try recompiling
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\analytics\ext\python27\lib\site-packages\statsmodels-0.5.0-py2.7-win32.egg\statsmodels\formula\__init__.py",
line 4, in <module>
from formulatools import handle_formula_data
File "C:\analytics\ext\python27\lib\site-packages\statsmodels-0.5.0-py2.7-win32.egg\statsmodels\formula\formulatools.p
y", line 1, in <module>
import statsmodels.tools.data as data_util
File "C:\analytics\ext\python27\lib\site-packages\statsmodels-0.5.0-py2.7-win32.egg\statsmodels\tools\__init__.py", li
ne 1, in <module>
from tools import add_constant, categorical
File "C:\analytics\ext\python27\lib\site-packages\statsmodels-0.5.0-py2.7-win32.egg\statsmodels\tools\tools.py", line
14, in <module>
from pandas import DataFrame
File "C:\analytics\ext\python27\lib\site-packages\pandas\__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
File "numpy.pxd", line 157, in init pandas.tslib (pandas\tslib.c:49133)
ValueError: numpy.dtype has the wrong size, try recompiling
(to expand a bit on my comment)
Numpy developers follow in general a policy of keeping a backward compatible binary interface (ABI). However, the ABI is not forward compatible.
What that means:
A package, that uses numpy in a compiled extension, is compiled against a specific version of numpy. Future version of numpy will be compatible with the compiled extension of the package (for exception see below).
Distributers of those other packages do not need to recompile their package against a newer versions of numpy and users do not need to update these other packages, when users update to a newer version of numpy.
However, this does not go in the other direction. If a package is compiled against a specific numpy version, say 1.7, then there is no guarantee that the binaries of that package will work with older numpy versions, say 1.6, and very often or most of the time they will not.
The binary distribution of packages like pandas and statsmodels, that are compiled against a recent version of numpy, will not work when an older version of numpy is installed.
Some packages, for example matplotlib, if I remember correctly, compile their extensions against the oldest numpy version that they support. In this case, users with the same old or any more recent version of numpy can use those binaries.
The error message in the question is a typical result of binary incompatibilities.
The solution is to get a binary compatible version, either by updating numpy to at least the version against which pandas or statsmodels were compiled, or to recompile pandas and statsmodels against the older version of numpy that is already installed.
Breaking the ABI backward compatibility:
Sometimes improvements or refactorings in numpy break ABI backward compatibility. This happened (unintentionally) with numpy 1.4.0.
As a consequence, users that updated numpy to 1.4.0, had binary incompatibilities with all other compiled packages, that were compiled against a previous version of numpy. This requires that all packages with binary extensions that use numpy have to be recompiled to work with the ABI incompatible version.
For me (Mac OS X Maverics, Python 2.7)
easy_install --upgrade numpy
helped. After this you can install up-to-date packages pandas, scikit-learn, e.t.c. using pip:
pip install pandas
I found it to be a simple version being outdated or mismatch and was fixed with:
pip install --upgrade numpy
pip install --upgrade scipy
pip install --upgrade pandas
Or might work with the one liner:
pip install --upgrade numpy scipy pandas
I had a similar error with another library and realized that I had several versions of numpy installed on my system. The fix for me was to edit my PYTHONPATH and put the site-packages that contained the latest version of numpy in first position.
As in here, for me only sudo pip install pandas==0.13.1 worked
I also encounter this error when use pandas to access MYSQL.
This error message indicates a binary compatible issue and can be resolved by
using latest version of pandas and numpy package.
Here is my steps to resolve this issue, and it works well on my Ubuntu 12.04:
cd /tmp/
wget https://pypi.python.org/packages/source/p/pandas/pandas-0.12.0.tar.gz
tar xzvf pandas-0.12.0.tar.gz
cd pandas-0.12.0
easy_install --upgrade numpy
In my case, I had installed pandas-0.10.0.win-amd64-py2.7 but was checking to see if a bug had been fixed in a more recent version of pandas. So I did an easy_install -U to force the upgrade, but then got the above error due to some incompatibilities with numpy etc... when I did
import pandas
To fix, I just reinstalled the pandas-0.10.0.win-amd64-py2.7 binary and everything works. I didn't see this answer (suggests to use pip) which may have helped me (though not sure) Install particular version with easy_install
Also this highlights why one should use virtualenv (which I wasn't).
For me (Mac OS X Mavericks) it worked to install the version for python2.6:
sudo port install py26-scikit-learn
then run:
python2.6 myscript.py
The problem I solved on Webfaction was old numpy library(1.5) which was in conflict with my fresh
pip install pandas
installation in .virtualenv.
The problem was solved after I did pip install pandas out of the virtual environment.
The idea came from discussion on https://github.com/pydata/pandas/issues/3711, thanks, cpcloud!
I just meet this 'ValueError' issue and have addressed it. Definitely there's something wrong with numpy package.
But when I try to pip install --upgrade numpy it failed, so I uninstall and download the newest numpy.zip file.
Then manually uncompress and python setup.py install it.
Luckly, it works!
Like #user333700 said, required versions of libraries may not meet for each other. You get one library as another's dependency. Then without knowing it was already installed as dependency, you need that specific library and you install one version. With such ways dependencies may mess up.
I lived such a case and looked for a solution. Found this:
https://stackoverflow.com/a/12975518/1694344
I had two different versions for egg-info file and folder name of numpy:
drwxr-xr-x. 19 root root 4096 Sep 25 15:00 numpy
drwxr-xr-x. 2 root root 4096 Sep 22 11:25 numpy-1.13.1.dist-info
-rw-r--r--. 1 root root 1630 Nov 20 2015 numpy-1.7.1-py2.7.egg-info
I removed them all and reinstalled numpy with pip.
I had a similar issue, and simply re-installing using pip install ... as suggested in previous comments didn't work.
What worked for me was re-installing with the added flag pip install --no-cache-dir ..., seems there was an incompatible numpy version somewhere in the cache.
There are cases where you want to keep a specific NumPy version and the upgrade option mentioned here will not work.
An example that occurred to me was the Python distribution preinstalled with ArcGIS. For ArcPy to work in ArcGIS 10.5.1, that distribution needs to be Python 2.7.12 with NumPy 1.9.3 and any other version of NumPy is probably going to cause issues with your ArcPy functionality.
What you can do with this case is try to install a specific, older version of the problematic third-party library that is supposed to be compatible with the older NumPy version that ArcGIS has.
For instance, scikit-learn 0.19.1 would NOT operate with NumPy 1.9.3 and would result in the same error you mentioned. However, scikit-learn 0.15 works fine. You can test different versions to find the one that works. Just mention the version number through pip:
python -m pip install scikit-learn==0.15

Categories