I'm trying to import sklearn, however when I attempt to do so I receive the following:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-8fd979e02004> in <module>()
----> 1 import sklearn
C:\Users\Alpine\AppData\Local\Enthought\Canopy\User\sklearn\__init__.py in <module>()
29 # process, as it may not be compiled yet
30 else:
---> 31 from . import __check_build
32 from .base import clone
33
C:\Users\Alpine\AppData\Local\Enthought\Canopy\User\sklearn\__check_build\__init__.py in <module>()
44 from ._check_build import check_build
45 except ImportError as e:
---> 46 raise_build_error(e)
C:\Users\Alpine\AppData\Local\Enthought\Canopy\User\sklearn\__check_build\__init__.py in raise_build_error(e)
39 to build the package before using it: run `python setup.py install` or
40 `make` in the source directory.
---> 41 %s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
42
43 try:
ImportError: No module named _check_build
___________________________________________________________________________
Contents of C:\Users\Alpine\AppData\Local\Enthought\Canopy\User\sklearn\__check_build:
setup.py setup.pyc _check_build.c
_check_build.pyx __init__.py __init__.pyc
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line string', (1, 2))
I'm fairly sure that scikit-learn has been correctly built as I managed to run python setup.py install without any incident. I did however try running python setup.py bdist_wininst -b doc/logos/scikit-learn-logo.bmp though was interrupted at error: cannot copy tree 'build\scripts.win-amd64-2.7': not a directory.
Might anybody have an idea on how to fix this?
I have the same problem on Windows 10. I installed Anaconda with Python 3.7 and this installation shipped not only this problem. To solve run in anaconda prompt:
conda install scikit-learn
At least this worked for me
OK, the following is work for me :)
sudo make
sudo python setup.py install
Finally, to test whether installation is ok:
nosetests --exe sklearn
One way to avoid this error is to make sure you have all the needed dependencies installed. Under Ubuntu / Debian, you can accomplish this by running the following:
sudo apt-get build-dep python-sklearn
This doesn't exactly fit your question as it doesn't involve Enthought distribution; however, I had a similar problem with a module using sklearn. The error was something like:
$ python -m somefile.py // somefile.py uses sklearn at some point
Cannot import name __check_build
And after I installed scikit-learn (also,scipy and numpy-MKL) from this page the problem seemed to go away.
Make sure you are executing the code with the latest python version. If you have multiple python version installed in your machine then just remove the first line "#!/usr/bin/python" and try running with full path of latest python version like "/usr/local/bin/python3.4 'filename'". If you have python version lower than 2.7 then try upgrading the version and installing the dependencies and then try the above method.
In my case I had Python installed at two places, first by myself where I independently installed python and it was in a separate folder, second time by anaconda which installs python within its own folder. So every-time I called Scikit Learn it was refereeing to the first python folder which had some issues with scikit learn but when I removed old Python folder completely jupyter notebook was refereeing to the correct python folder and hence it worked.
I am using Anaconda and this worked for me:
conda install scikit-learn
Related
I am trying to download Google Cloud DLP on my Mac M1 running macOS Monterey. I am using Python 3.10.4 and pip 22.0.4.
I first tried using pip install google-cloud-dlp, but got an error when I went to import it that I have the wrong architecture (arm instead of x86-64 – hence M1 error).
I then uninstalled DLP and followed the advice of a StackOverflow post to download the library directly from GitHub. I did this, navigated to the directory, and ran sudo python3 setup.py install.
Now, when I try to import the library, I get the error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [57], in <cell line: 1>()
----> 1 import google.cloud.dlp
ModuleNotFoundError: No module named 'google.cloud.dlp'
This is odd because when I run pip list I get this in the output:
google-api-core 2.7.2
google-auth 2.6.6
google-cloud-dlp 3.6.2
googleapis-common-protos 1.56.0
Now, when I run pip install google-cloud-dlp, I get a bunch of "Requirement already satisfied" messages, yet when I try to import, I get a ModuleNotFoundError.
I have tried importing in Atom, VSCode, and Jupyter-Notebook, and still get a ModuleNotFoundError. I feel dumb asking this question because it seems like it would be an easy fix, but any help is appreciated.
One potential issue is that you have multiple python versions installed. Is it possible that the script ran under in a different Python environment than the one used to print the installed versions?
Could you try following these steps?
Create virtualenv.
python3 -m venv env
source env/bin/activate
Install google-cloud-dlp.
pip install google-cloud-dlp
Run code.
$ python3
>>>import google.cloud.dlp
>>>
If you're still having trouble, try the steps on another environment like Cloud Shell to rule out an issue with your specific environment.
I'm using a Kubernetes inventory builder script found here: https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py
On line 36, the ruamel YML library is imported using the code from ruamel.yaml import YAML. This library can be found here: https://pypi.org/project/ruamel.yaml/
On my OSX device (Mojave 10.14.3), if I run pip list, I can clearly see the most up to date version of ruamel.yaml:
If I run pip show ruamel.yaml, I get the following output:
I'm running the script with this command: CONFIG_FILE=inventory/mycluster/hosts.ini python3 contrib/inventory_builder/inventory.py 10.0.0.1 10.0.0.2 10.0.0.4 10.0.0.5
Bizarrely, it returns the following error:
Traceback (most recent call last):
File "contrib/inventory_builder/inventory.py", line 36, in <module>
from ruamel.yaml import YAML
ModuleNotFoundError: No module named 'ruamel'
I have very little experience with Python, so don't understand how this could be failing. Have I installed the library incorrectly or something? From the documentation on the ruamel.yml project page, it looks like the script is calling the library as it should be.
Thanks in advance
In my case, I was installing this with pip3 install ruamel.yaml, and it was puting the package in /usr/local/lib/python3.9/site-packages/, but the python3 binary on the machine was pinned to Python 3.7, so trying to import that module was sending the ModuleNotFoundError message.
What helped to fix this, was to install the module with python3 -m pip install ruamel.yaml, running pip via the python3 binary makes sure it runs on the same version, in this case 3.7, and gets installed via the correct version number site-packages.
pip is set to point to the Python 2 installation. To install the library under Python 3, do pip3 install ruamel.yml.
you're using python 3 and want to use the package that is with python 2. Go to the directory where your python 3 is, navigate to Scripts and use the pip in there to install the needed library.
This helped me (adding version number to python):
CONFIG_FILE=inventory/mycluster/hosts.yaml python3.6 contrib/inventory_builder/inventory.py ${IPS[#]}
[python 3.10.x].
There is no package called ruamel.yaml
what worked is pip install ruamel-yaml
I was using Jupyter Notebook to do some studying today and noticed that I couldn't import Tensorflow or Keras. It was strange because until yesterday it was working fine. Anyway, I looked online and some people recommended I install Jupyter again using conda install jupyter notebook. I did exactly that and now I can't even import Tensorflow or NumPy. Not to mention whenever I try to open Jupyter that doesn't work either. I see a command prompt flash briefly and then nothing happens.
When I try to import either, I get this error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\numpy\core\__init__.py in <module>
39 try:
---> 40 from . import multiarray
41 except ImportError as exc:
~\Anaconda3\lib\site-packages\numpy\core\multiarray.py in <module>
11
---> 12 from . import overrides
13 from . import _multiarray_umath
~\Anaconda3\lib\site-packages\numpy\core\overrides.py in <module>
5
----> 6 from numpy.core._multiarray_umath import (
7 add_docstring, implement_array_function, _get_implementing_args)
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-0aa0b027fcb6> in <module>
----> 1 import numpy as np
~\Anaconda3\lib\site-packages\numpy\__init__.py in <module>
140 from . import _distributor_init
141
--> 142 from . import core
143 from .core import *
144 from . import compat
~\Anaconda3\lib\site-packages\numpy\core\__init__.py in <module>
69 Original error was: %s
70 """ % (sys.executable, exc)
---> 71 raise ImportError(msg)
72 finally:
73 for envkey in env_added:
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
1. Check that you are using the Python you expect (you're using
C:\Users\seant\Anaconda3\python.exe),
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy versions you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: No module named 'numpy.core._multiarray_umath'
I tried reinstalling NumPy, but that didn't solve the issue. I installed Python and NumPy via installing Anaconda, and my operating system is Windows 10. My path variable looked normal as well and everything was working until now. Does anyone know how I can proceed to fix this issue?
Go to your terminal and locate the environment where you have Numpy and the other modules installed. If your'e using virtualenvwrapper you can run:
lsvirtualenv a list of your virtual envs you have will be displayed.
Then type workon virtualenv1 (replace with name of displayed virtual env) and check for your installed modules e.g after selecting the virtual env you can then type
python and get into the shell. Then you can do import numpy etc to check if the modules youre looking for exist in that virtualenv. When you find them you can then exit out of the shell and do a pip install jupyter to install jupyter notebooks on the virtual env with the modules you need. To avoid meeting such problems in future you should make sure you maintain virtual environments in your machine with the modules that your're interested to work with as per virtual env. Virtualenvwrapper is a great tool that abstracts away most of the common pitfalls found with working with virtual envs. More info in managing and creating virtual envs can be found here.
In my case I just spent around an hour uninstalling everything Python-related (Python, Anaconda, etc.) and completely installing everything from scratch again. It was a bit of a pain but I didn't know what else to do without having to dive too deeply into the issue.
I'm using Anaconda 5.0.1 with Python 2.7.14. When I open a jupyter notebook and try to run the following:
%matplotlib inline
I get the following error:
ImportError Traceback (most recent call last)
C:\toolkits.win\anaconda2\envs\dlc\lib\site-packages\matplotlib\font_manager.py in <module>()
56
57 import matplotlib
---> 58 from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir
59 from matplotlib.compat import subprocess
60 from matplotlib.fontconfig_pattern import (
ImportError: DLL load failed: The specified procedure could not be found.
When I try to drill into the error, the problem is with ft2font:
In [1]: from matplotlib import ft2font
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-a32e7826851f> in <module>()
----> 1 from matplotlib import ft2font
ImportError: DLL load failed: The specified procedure could not be found.
I double-checked and made sure freetype is installed:
(dlc) C:\Users\Larry>conda install freetype
Fetching package metadata .............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\toolkits.win\anaconda2\envs\dlc:
#
freetype 2.8 vc9hf582001_0 [vc9]
Any ideas?
conda install freetype --force-reinstall
Improving a bit on the above suggestion:
pip install matplotlib --force-reinstall
def _check_versions():
# Quickfix to ensure Microsoft Visual C++ redistributable
# DLLs are loaded before importing kiwisolver
from . import ft2font
Try install Microsoft Visual C++ redistributable
My solution: unstall matplotlib, and re-install it with pip.
I have the same issue and on my machine the problem was that Java (openJDK) was mentioned in the PATH-variable prior to Python (Anaconda in my case).
If you open a cmd and type
echo %PATH%
you can check if that is the case on your machine as well. If it states ...\Java\openJDK<version>\bin is before the Anaconda directories, the wrong freetype.dll library is getting found and the error occurs.
All you have to do is to change PATH to state the anaconda directories before the Java directories. This may raise another set of issues with Java though...
I found that if conda doesn't activate when the terminal starts up properly, you get this error.
I found that by opening the terminal, typing a bunch of stuff and pressing enter a a lot to prevent conda from activating and then when I tried to run a matplotlib inclusive script it would give me this error, but when I let it start without interference, it would not give me this error (it would run fine, at least past this error).
Considering this, it may be useful to keep import matplotlib at the top of the file if possible, so you don't wait a while and then find out that matplotlib won't load.
I solved this problem by installing the last Microsoft Visual C++ redistributable 2019.
In my case :
python 3.8.7
matplotlib : 20.3.3
test.py
result in IDLE
Debugged into same issue. It seems another access-deny issue.
Solution: Re-install matplotlib in elevated mode.
Launch Anaconda Prompt as Administrator
Run conda install matplotlib
Finish installing any required packages.
I was following this guide https://realpython.com/blog/python/setting-up-a-simple-ocr-server/ and got to the part where I run cli.py python flask_server/cli.py but I get
python cli.py
Traceback (most recent call last):
File "cli.py", line 3, in <module>
import pytesseract
ImportError: No module named pytesseract
How can I solve this ?
I also saw that I have multiple versions of python. I have linux-kali installed with the latest updates.
Something else: he runs the command like python flask_server/cli.py- where is that flask_server located ? I simply ran it like python cli.py(I was in some directory in which I created the file).
Python import errors usually boils down to one of those three cases (whether is is modules you developed; or modules distributed as packages):
You did no install the required package. Googling pytesseracttells me its an OCR that is distributed and installable using Python package manager tool pip by running pip install pytesseract in your favorite shell.
You did install the package, but is is not in your python path.
(Less often) You did install the package, and it is in your python path, but you used a name already in user by Python, and the two are conflicting.
In your case, I strongly think this is the first one. Case 2. and 3. can be assessed by calling python -v your_script.pyas described in this answer.
I had a similar error. So I hope to help people with this kind of problems.
In my case,
I tried to run python code using pytesseract lib on Raspberry pi 3.
$ pip install pillow
$ pip install pytesseract
(followed by https://www.pyimagesearch.com/2017/07/10/using-tesseract-ocr-python/)
and then, I made an example.py to test.
example.py
try:
import Image
except ImportError:
from PIL import Image
from pytesseract import *
print(pytesseract.image_to_string(Image.open('YOUR_IMAGE_PATH')))
and then, when I run this code, I got below error like you.
ImportError: No module named pytesseract
After I saw the #Bertrand Caron's answer, I found a solution.
My problem was package library path.
I also have multiple versions of python, 2.7 and 3.5, like a writer.
When I run command $python --version on linux, the result is Python 2.7.13.
In my case, when I installed a pytesseract package,
it was stored in "/usr/local/lib/python3.5/dist-packages/pytesseract".
And When I ran $python -v example.py, I found the referenced packages path hadn't been same with upper pytesseract package directory.
cf.
installed pytesseract path : /usr/local/lib/python3.5/dist-packages/pytesseract
actual referenced lib path, when running : /usr/lib/python2.7/dist-packages/
So, I copied pytesseract, located in "/usr/local/lib/python3.5/dist-packages/pytesseract" to "/usr/lib/python2.7/dist-packages/"
Then, Solved!
In my case, I was running it in Jupyter so I used this command,
! pip install --user pytesseract
But I forgot to restart the kernal. You need to restart the kernal after installing the pakcage
I had the same error. My solution is
$ pip3 install pytesseract
since I have python 2 and python 3 installed together.