Note upfront: I tried following suggestions in other threads, but so far, haven't found anything that helps (1, 2)
I received a pandas file that I would like to run on my machine. In the beginning, the code references the sklearn package.
import re
from sklearn.decomposition import FactorAnalysis
from sklearn import svm
I do, however, get the following error when running this cell:
ModuleNotFoundError: No module named 'sklearn.decomposition'
I do have the scikit_learn-0.19.0-py3.6.egg-info and sklearn packages in my Python directory, so I'm not sure why it doesn't work. I tried reinstalling it, but both...
conda install scikit-learn
...and...
pip install scikit-learn
...don't work. The former crashes my Python (pop-up window telling my it has crashed), the latter produces a bunch of error messages:
>pip install scikit-learn
Requirement already satisfied: scikit-learn in c:\programdata\...\lib\site-packages
Exception:
Traceback (most recent call last):
File "C:\ProgramData\...\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\ProgramData\...\lib\site-packages\pip\commands\install.py", line 335, in run
wb.build(autobuilding=True)
File "C:\ProgramData\...\lib\site-packages\pip\wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "C:\ProgramData\...\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "C:\ProgramData\...\lib\site-packages\pip\req\req_set.py", line 666, in _prepare_file
check_dist_requires_python(dist)
File "C:\ProgramData\...\lib\site-packages\pip\utils\packaging.py", line 48, in check_dist_requires_python
feed_parser.feed(metadata)
File "C:\ProgramData\...\lib\email\feedparser.py", line 175, in feed
self._input.push(data)
File "C:\ProgramData\...\lib\email\feedparser.py", line 103, in push
self._partial.write(data)
TypeError: string argument expected, got 'NoneType'
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Any idea how I can get it to work? Thanks
Try running that last command to upgrade pip first?
pip install --upgrade pip
And then install scikitlearn afterwards. And possibly try this depending on what version of python you're using in your environment:
pip3 install scikit-learn
Solved it.
Managed to roll-back to pip v9 using this thread.
Uninstalled scikit-learn (which was v0.19). Had to use Admin mode to avoid the PermissionError mentioned before
Installed it again (which was v0.2)
Code works now, thanks all who contributed.
If you are on linux...
1). download anaconda https://www.anaconda.com/download/#download
2). go to where the file is downloaded and type bash Anaconda-latest-Linux-x86_64.sh
The new anaconda already comes with scikit-learn installed.
If you need an older version of python like I did you can install that version by typing
conda install python=3.6
Actually, I was facing the same problem in windows10 recently for python3 then I try this it worked for me.
1. python -m pip install -U pip setuptools
2. pip install scikit-learn
Related
A program I am trying to install requires the installation of PyQt5 5.15.0 , which gives me this error. The odd thing is that the installation works fine for the latest version of PyQt5 (5.15.2), but this program requires 5.15.0 specifically.
Command Output:
Collecting PyQt5==5.15.0
Using cached PyQt5-5.15.0.tar.gz (3.3 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... error
ERROR: Command errored out with exit status 1:
command: 'c:\users\mshal\appdata\local\programs\python\python39\python.exe' 'C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\mshal\AppData\Local\Temp\tmp41s11ev6'
cwd: C:\Users\mshal\AppData\Local\Temp\pip-install-sfw90hvc\pyqt5_e2cc46859b554da7b84798abae5378ba
Complete output (31 lines):
Traceback (most recent call last):
File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 126, in prepare_metadata_for_build_wheel
hook = backend.prepare_metadata_for_build_wheel
AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 280, in <module>
main()
File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 263, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 130, in prepare_metadata_for_build_wheel
return _get_wheel_metadata_from_wheel(backend, metadata_directory,
File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 159, in _get_wheel_metadata_from_wheel
whl_basename = backend.build_wheel(metadata_directory, config_settings)
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\api.py", line 51, in build_wheel
project = AbstractProject.bootstrap('pep517')
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\abstract_project.py", line 83, in bootstrap
project.setup(pyproject, tool, tool_description)
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\project.py", line 479, in setup
self.apply_user_defaults(tool)
File "project.py", line 62, in apply_user_defaults
super().apply_user_defaults(tool)
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\pyqtbuild\project.py", line 79, in apply_user_defaults
super().apply_user_defaults(tool)
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\project.py", line 225, in apply_user_defaults
self.builder.apply_user_defaults(tool)
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\pyqtbuild\builder.py", line 66, in apply_user_defaults
raise PyProjectOptionException('qmake',
sipbuild.pyproject.PyProjectOptionException
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\mshal\appdata\local\programs\python\python39\python.exe' 'C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\mshal\AppData\Local\Temp\tmp41s11ev6' Check the logs for full command output.
I am on the latest version of pip. Any ideas on the root cause of this issue?
What helped me is upgrading pip from 20.2.3 to the latest one (in my case 21.1.1)
For Mac/Homebrew users.
The answer by #the-x is leading in the right direction. On a Mac with QT5 installed via Homebrew the qmake binary just needs to be added to the path. This can be achieved through
export PATH="/opt/homebrew/opt/qt5/bin:$PATH"
(of course depending on where the homebrew files are installed)
Running on arm with python3.6 (ubuntu18 on nvidia Xavier):
sudo apt install qt5-default
For MacOS users.
I am on Apple M1 silicon using Python 3.9.8. What worked for me was #Apaul's comment in the original question section. Install pyqt5-sip prior to pyqt5.
I also have an Intel Mac and on that machine, I do not need to do this.
Checking the binaries that PyQt5 provides in pypi for version 5.15.0 I see that it does not provide the binaries for python3.9 in windows, so pip is trying to compile using the source code which is complicated and can generate several dependency problems (for example you must have Qt 5.15 installed, etc). So my recommendation is to install a more updated version of PyQt5, for example 5.15.2 since if it provides the binaries for python3.9 on windows, in addition to being a wrapper of an LTS version of Qt then it will have solved several bugs.
python -m pip install PyQt5==5.15.2
Another solution is to use python3.8 instead of python3.9 so that you can install pyqt5 5.15.0 from pypi without problems.
Upgrading your pip enables you to install PyQt5. Personally, I had the same issue while installing PyQt6 and I upgraded my pip, and everything installed perfectly. I think both python and pip versions play an important role in installing PyQt so make sure you have later versions.
This is the command I used in Linux:
pip install --upgrade pip
Combining several answers on this question: On an Apple M1 Pro Macbook with macOS Ventura 13.0.1, with Homebrew 3.6.17 and python 3.11.0 the following commands fixed it for me (no sudo):
brew install qt5
export PATH="/opt/homebrew/opt/qt5/bin:$PATH"
python3 -m ensurepip --default-pip
pip3 install pyqt5-sip
pip3 install pyqt5 --config-settings --confirm-license= --verbose
That last step calls qmake to compile all of Qt on your M1 and takes many minutes to complete, be patient and let it finish.
Since qt5-default was not available, I installed qt5-default's dependencies
sudo apt-get install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools
after that I installed pyqt5 via apt-get first and afterwards via pip
sudo apt-get install pyqt5-dev
pip install pyqt5
now wheel seems to work
side-note:
I am not sure if sudo apt-get install pyqt5-dev is even necessary
The error message thrown here is misleading - it's not an issue with a sipbuild.api attribute. Indeed, in this case program qmake is missing, see last line of the Python traceback. Have a look if it's installed on your system and add it to your PATH variable. Otherwise, install it. On Linux this would be done with
sudo apt-get install qt5-qmake
I had this problem on my M1 Mac using Python 3.9.12 when I was trying to install a library: pip install pixellib.
The first thing I did was: pip install pixellib --verbose to see the whole log, and there I noticed that PyQt5 was waiting for an input. So then I found someone else with that issue, and used pip install pyqt5 --config-settings --confirm-license= --verbose which took some time to compile, but worked!
I could not get any of the above solutions to work but I managed to get it working using python3.9, PyQt5=5.15.2, pip=22.0.2 and sip=6.5.0 by using sudo apt-get install PyQt5. If you need it in a virtual environment, you can manually copy the PyQt5 folder from your default /usr/lib/python3/dist-packages to the site-packages folder in your virtual environment.
To all those that are struggling with Apple M1 installation, here is a working solution, specifically addressing the problem of installing the pixellib library that depends on PyQt5 but you can apply it equally to other libs:
PyQt5 is not supported on Apple M1, it needs qt6: https://www.reddit.com/r/learnpython/comments/o4w1ut/comment/h2jele3/?utm_source=share&utm_medium=web2x&context=3 , https://www.qt.io/product/qt6
this means you need to install PyQt6: python3 -m pip install PyQt6
go to the lib you need, in my case pixellib: https://pypi.org/project/pixellib/#files and
download the wheel file
get the wheel tool: pip install wheel
unpack the wheel wheel unpack pixellib-0.7.1-py3-none-any.whl
Change its dependency of PyQt5 to PyQt6
edit pixellib-0.7.1/pixellib-0.7.1.dist-info/METADATA
pyQt5 => pyQt6
pack it back wheel pack pixellib-0.7.1
install it: pip install pixellib-0.7.1-py3-none-any.whl
test in python: `
# should work
import pixellib
P.S. thanks to Terra and ChaOS for supporting work on the project underlying this report.
I finally managed to make it works on M1/M2 Macbook Pro.
None of these answers worked for me, so I looked at brew to install pyqt.
The following command will install pyqt5 via brew:
brew install pyqt#5
Then it just worked.
This can be resolved by switching to an environment with Python >= 3.8
I am trying to run the PyCharm profiler but I get the following error message:
Traceback (most recent call last):
File "/home/b3053674/ProgramFiles/pycharm-2017.1.4/helpers/profiler/run_profiler.py", line 164, in <module>
profiler.run(file)
File "/home/b3053674/ProgramFiles/pycharm-2017.1.4/helpers/profiler/run_profiler.py", line 89, in run
execfile(file, globals, globals) # execute the script
File "/home/b3053674/Documents/pycotools/pycotools/tasks.py", line 38, in <module>
import viz,errors, misc, _base, model
File "/home/b3053674/Documents/pycotools/pycotools/viz.py", line 53, in <module>
import matplotlib.pyplot as plt
File "/home/b3053674/anaconda2/envs/pycotools/lib/python2.7/site-packages/matplotlib/__init__.py", line 124, in <module>
from . import cbook
ImportError: cannot import name cbook
Snapshot saved to /home/b3053674/.PyCharm2017.1/system/snapshots/pycotools30.pstat
Process finished with exit code 1
I am using a conda environment which I have switched to in the terminal:
$ source activate <env>
then updated matplotlib
$pip install matplotlib --upgrade
and six just for good measure
$pip install six --upgrade
(note that I've also manually deleted these packages from site-directory of my environment and reinstalled just incase --upgrade wasn't behaving)
I've looked here and here and neither solutions solved my problem.
I've also switched the PyCharm Run configurations to use each of my conda environments in turn all of which produce the same error.
Note that the profiler has worked before in the past and the code works fine when I use the normal way of executing the code. Does anybody have any idea of what is going on?
Thanks
I encountered the same error today, although probably for a different reason - the packages for matplotlib and/or six appear to be broken.
Resolved it by downgrading to the previous versions:
conda install six=1.10.0
conda install matplotlib=2.0.2
I had the same issue.
Downgrading to matplotlib 2.0.2 seems to fix it.
pip uninstall matplotlib
pip install matplotlib==2.0.2
I had this error in jupyter but not IPython. Fixed with $ conda install matplotlib=2.0.2 as above but six not downgraded. Don't forget (as I did) to restart the kernel.
I've looked at a number of posts on this and nothing seems to fix it. I initally started out on Python 3.5, heard that there were several unresolved issues with pip and so I uninstalled and reinstalled Python 3.4.4 -
I want to use pyautogui for a work task, but when I try to install pyautogui directly after Python3.4.4 installation it tells me the PIL Module can't be found. I read in another article to install 3.4.4 and update pip, then install pyautogui. Cool, so I installed 3.4.4, I needed to upgrade pip. So I entered in
Scripts\pip.exe install --upgrade pip
from the command line in the root folder. Every time I get this
Exception:
Traceback (most recent call last):
File "h:\python34\lib\shutil.py", line 527, in move
os.rename(src, real_dst)
PermissionError: [WinError 32] The process cannot access the file because it is
being used by another process: 'h:\\python34\\scripts\\pip.exe' -> 'C:\\Users\\z
jf\\AppData\\Local\\Temp\\pip-qo75adq9-uninstall\\python34\\scripts\\pip.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "h:\python34\lib\site-packages\pip\basecommand.py", line 211, in main
File "h:\python34\lib\site-packages\pip\commands\install.py", line 311, in run
File "h:\python34\lib\site-packages\pip\req\req_set.py", line 640, in install
File "h:\python34\lib\site-packages\pip\req\req_install.py", line 716, in unin
stall
File "h:\python34\lib\site-packages\pip\req\req_uninstall.py", line 125, in re
move
File "h:\python34\lib\site-packages\pip\utils\__init__.py", line 315, in renam
es
File "h:\python34\lib\shutil.py", line 540, in move
os.unlink(src)
PermissionError: [WinError 32] The process cannot access the file because it is
being used by another process: 'h:\\python34\\scripts\\pip.exe'
Thing is, nothing is running in that folder. I don't have windows explorer open to it, I don't have anything accessing any files in there, and I'm obviously running it from an upper level directory using the command line. So I have no idea why it's saying that pip.exe is being used by another process. The only process it's being run by is itself and if that's the issue, then how in the world are you supposed to upgrade it?
**EDIT: ** Per the accepted answer, in order to get PIP to update I used the command
python -m pip install -U pip
Once that worked I tried to install pyautogui yet again. It still said that PIL module could not be found. PIL is the Python Image Library. I installed it using
python -m pip install image
And once that worked I then installed pyautogui like so
python -m pip install pyautogui
To upgrade pip on windows google "upgrade pip on windows" or alternately run this in a command prompt:
python -m pip install -U pip
This is a known issue on windows where an executable can't be overwritten while it's running. Sorry no links handy but it should be easy to find more details.
Problem: You are using pip version 18.1, however version 19.0.1 is available. You should consider upgrading via the ‘python -m pip install –upgrade pip’ command.
Solution: In order to upgrade PIP in Windows, you’ll need to open the Windows Command Prompt, and then type/copy the command below. Note that the following method would only work if you already added Python to Windows path. Don’t worry if you don’t know what it means, as I’ll show the full steps to upgrade pip in windows in the next section.
python -m pip install --upgrade pip
After updating a package (IPython in my case) using pip install -U ipython running any Python script that uses entry points fails with this error:
Traceback (most recent call last):
File "/home/adrian/dev/indico/env/bin/indico", line 5, in <module>
from pkg_resources import load_entry_point
...
File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 94, in __init__
requirement_string[e.loc:e.loc + 8], requirement_string))
pkg_resources._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'< 2.0'"
Nothing else changed, I did not update any other libraries.
This is caused by an issue in setuptools==20.2.1 which is pulled in by IPython (setuptools>..), so a pip install -U updated it.
Until a fixed version is released or the broken version is pulled from PyPI there is a simple workaround (but note that it will break again if something updates setuptools):
pip install -U pip
pip uninstall setuptools
pip install 'setuptools<20.2'
The pip update is needed since older versions of pip will not work without setuptools being installed
See these IRC logs and BitBucket issue for details:
http://chat-logs.dcpython.org/day/pypa/2016-02-25
https://bitbucket.org/pypa/setuptools/issues/502/packaging-164-does-not-allow-whitepace
Try downgrading your pip to 8.1.1:
pip install pip==8.1.1
That solved it for me.
In my case I had package = "2.8.0" in my Pipfile. Changing it to package = "==2.8.0" fixed this error for me.
I was trying to follow the instruction from this link :http://www.thisisthegreenroom.com/2011/installing-python-numpy-scipy-matplotlib-and-ipython-on-lion/
However, it seems my python can not find the Numpy, Scipy and everything I install using pip.
Right now, when I type which python, it shows /usr/local/bin/python.
However, when I type
pip install numpy
it shows
Requirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python.
Thus it seems they are in different directory, and probably I installed numpy previously, which makes pip keep telling me they are installed. I wonder is there any way around that ?
update, I have tried to import it.
import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
I have also tried to uninstall the numpy and install it again. However, when I uninstall it. It still gives me error.
applematoMacBook-Air:~ apple$ pip uninstall numpy
DEPRECATION: Uninstalling a distutils installed project (numpy) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling numpy-1.8.0rc1:
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info
Proceed (y/n)? y
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip-6.1.1-py2.7.egg/pip/basecommand.py", line 246, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip-6.1.1-py2.7.egg/pip/commands/uninstall.py", line 70, in run
requirement_set.uninstall(auto_confirm=options.yes)
File "/usr/local/lib/python2.7/site-packages/pip-6.1.1-py2.7.egg/pip/req/req_set.py", line 274, in uninstall
req.uninstall(auto_confirm=auto_confirm)
File "/usr/local/lib/python2.7/site-packages/pip-6.1.1-py2.7.egg/pip/req/req_install.py", line 730, in uninstall
paths_to_remove.remove(auto_confirm)
File "/usr/local/lib/python2.7/site-packages/pip-6.1.1-py2.7.egg/pip/req/req_uninstall.py", line 126, in remove
renames(path, new_path)
File "/usr/local/lib/python2.7/site-packages/pip-6.1.1-py2.7.egg/pip/utils/__init__.py", line 292, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
os.unlink(src)
OSError: [Errno 13] Permission denied: '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info'
Seems like the version of pip you are using is using the default mac system-wide python interpreter /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python instead of the one installed in /usr/local/bin.
I've pretty much experienced the same issues until I started using homebrew. I'd recommend to have a look at this page on brew and python. You'd might need to remove pip and reinstall it from brew. Btw, using brew, there's no need for sudo.
try: pip uninstall numpy
and then: pip install numpy
...and try it with sudo:
sudo pip install numpy
first, you should use pip list to check out have you installed numpy .
if you already installed, check out your program IDE whether the pycharm, and check the pycharm interpreter does the local interpreter or virtual interpreter. if the interpreter is virtual, you should change to local. if it works, you can create the new project with select the local interpreter.
more detail: https://www.jianshu.com/p/9c3507cca2b9
in my problem, i can't update scikit-learn with pip install -U scikit-learn, and occur the problem
Cannot uninstall 'scikit-learn'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
it occured in your error too. so, i find your problem.
and i try the commod pip install -U --ignore-installed scikit-learn, and it solve my problem.