I have been trying to install and use scikit-learn and nltk. However, I get the following error while importing anything:
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/site-packages/sklearn/init.py", line 57, in
from .base import clone
File "/usr/local/lib/python2.7/site-packages/sklearn/base.py", line 11, in
from .utils.fixes import signature
File "/usr/local/lib/python2.7/site-packages/sklearn/utils/init.py", line 10, in
from .murmurhash import murmurhash3_32
File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling
I did a pip uninstall numpy followed by a pip install numpy and also a pip uninstall scikit-learn and again reinstalled it. But the error persists.
I met the same problem today. Now I have solved it.
Because I have installed numPy manually, and I use the command "pip" to install the else package.
Solve way:
find the old version of numPy.
You can import numPy and print the path of it.
delete the folder.
use pip to install again.
Related
Hi just updated my version of python from 3.7 to 3.8 I am using pycharm IDE and sklearn was working perfectly fine in the previous version but now when I try to run code that was
However after updating my version it keeps giving the following error.
"C:\Program Files\Python\python.exe" C:/Users/SmithyB/Desktop/test/K-Means.py
Traceback (most recent call last):
File "C:/Users/SmithyB/Desktop/test/K-Means.py", line 6, in <module>
from sklearn.cluster import KMeans
File "C:\Program Files\Python\lib\site-packages\sklearn\__init__.py", line 80, in <module>
from .base import clone
File "C:\Program Files\Python\lib\site-packages\sklearn\base.py", line 21, in <module>
from .utils import _IS_32BIT
File "C:\Program Files\Python\lib\site-packages\sklearn\utils\__init__.py", line 20, in <module>
from scipy.sparse import issparse
File "C:\Program Files\Python\lib\site-packages\scipy\__init__.py", line 119, in <module>
from scipy._lib._ccallback import LowLevelCallable
File "C:\Program Files\Python\lib\site-packages\scipy\_lib\_ccallback.py", line 1, in <module>
from . import _ccallback_c
ImportError: cannot import name '_ccallback_c' from 'scipy._lib' (C:\Program Files\Python\lib\site-packages\scipy\_lib\__init__.py)
I have made sure that the interpreter is correct. I have made sure that I have uninstalled older versions of python from my computer but unfortunately still no luck.
I will really appreciate it if someone can point out how to solve this problem.
Thanks
Try removing Scipy folder from C:/Users/SmithyB/AppData/Roaming/Python/Python36/site-packages/scipy
Reinstall using pip install scipy
Thanks for all your input, I couldn't have solved the problem without you guys.
I am posting how I solved the problem with the hope that it will be helpful to someone.
Since the problem was originally with using the SK-Learn library I uninstalled scikit-learn
pip uninstall scikit-learn
and then reinstalled it.
pip install scikit-learn
the error did not go away after that so I followed the suggestion of uninstalling scipy
pip uninstall scipy
and then reinstalling it.
pip install scipy
I ran a code that I had written which uses sklearn previously and it worked.
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
Python version : 3.5.2
I getting started with machine learning and things... So I installed sklearn and some other packages form pip. All of them were able to be installed successfully except sklearn so, I downloaded the wheel and installed it from here. It was successfully installed but when i tried to import it in the order to check correct installation, I got tons of error :
Traceback (most recent call last):
File "C:\MyFiles\Programs\Python\PlayGround.py", line 1, in
import sklearn
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\sklearn__init__.py", line 134, in
from .base import clone
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\sklearn\base.py", line 12, in
from .utils.fixes import signature
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\sklearn\utils__init__.py", line 11, in
from .validation import (as_float_array,
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\sklearn\utils\validation.py", line 18, in
from ..utils.fixes import signature
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\sklearn\utils\fixes.py", line 144, in
from scipy.sparse.linalg import lsqr as sparse_lsqr # noqa
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\sparse\linalg__init__.py", line 114, in
from .isolve import *
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\sparse\linalg\isolve__init__.py", line 6, in
from .iterative import *
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in
from . import _iterative
ImportError: DLL load failed: The specified module could not be found.
And the code was just :
import sklearn
I have already checked correct version of wheel package which, I have downloaded.
How can I correct it and why it is occurring?
The following steps solved my problem :
Uninstalling numpy, sklearn and scipy.
Downloading numpy+mkl and scipy from here.
Firstly installing numpy+mkl and then scipy.
Installing sklearn from pip.
Various things need to be checked:
Check numpy, scipy installation versions.
If they are correct then try to import numpy and scipy.
If they getting imported correctly, then clear your temp(c:/users/username/Appdata/local/temp)folder. Restart the machine and try again.
Still if doesn't work, then uninstall scipy, numpy , sklearn and
reinstall the proper wheel files
Download and install numpy+mkl file.
Currently you might have installed only the numpy file.
Go to: https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Download the corresponding wheel file in which is suitable for your python installation
pip install "/path_to_thefile/numpy-1.14.6+mkl-cp36-cp36m-win_amd64.whl"
This should help you
I'm going through the API tutorial on New Coder (this one) and got the following error when I try to run the program:
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9Traceback (most recent call last):
File "api.py", line 7, in <module>
import matplotlib.pyplot as plt
File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/artist.py", line 12, in <module>
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: numpy.core.multiarray failed to import
I know it isn't my code because I tried running it with the example code too and had the same issue. One answer I saw suggested on here was to try Numpy 1.8, but that didn't work either.
Also, all of this is set up within a virtual environment as directed so I don't think it's an issue of what I have installed elsewhere.
Installing packets from file with requirements may cause failures. I mean something like pip install -r requirements.txt
It seems to me that pip just installs packets in order without dependencies (first line from file, second line, ...).
I had same issue because of having installed numpy outside of environment and numpy after matplotlib in requirements.txt Pip compiled matplotlib with system nympy, after that it installed new numpy and nothing worked.
I just have switched strings and set matplotlib after numpy. Now it works.
Try this:
pip install numpy --upgrade
It works for me
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