Unable to install PyQt5 with pip - python

Im running into a problem installing PyQt5 with pip:
pip install pyqt5
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Collecting pyqt5
Using cached PyQt5-5.15.6.tar.gz (3.2 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
ERROR: Command errored out with exit status 1:
command: /opt/homebrew/opt/python#3.9/bin/python3.9 /opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/rv/nylh_sjx44b1bq2pmbn1lwkr0000gn/T/tmpi8zk3o59
cwd: /private/var/folders/rv/nylh_sjx44b1bq2pmbn1lwkr0000gn/T/pip-install-9w2kcz7l/pyqt5_a170d636f15d43c8bb4ae5d9a73574fc
Complete output (24 lines):
Querying qmake about your Qt installation...
/opt/homebrew/bin/qmake -query
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 156, 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 "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
main()
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 160, in prepare_metadata_for_build_wheel
whl_basename = backend.build_wheel(metadata_directory, config_settings)
File "/private/var/folders/rv/nylh_sjx44b1bq2pmbn1lwkr0000gn/T/pip-build-env-fyh98wta/overlay/lib/python3.9/site-packages/sipbuild/api.py", line 51, in build_wheel
project = AbstractProject.bootstrap('pep517')
File "/private/var/folders/rv/nylh_sjx44b1bq2pmbn1lwkr0000gn/T/pip-build-env-fyh98wta/overlay/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
project.setup(pyproject, tool, tool_description)
File "/private/var/folders/rv/nylh_sjx44b1bq2pmbn1lwkr0000gn/T/pip-build-env-fyh98wta/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 603, in setup
self.update(tool)
File "project.py", line 160, in update
sipbuild.exceptions.UserException
----------------------------------------
Im using macOS Monterey 12.0.1, with the Apple M1 chip.
What I've tried so far:
Installed PyQt5 using homebrew. Result: PyQt5 got installed via brew but without the necessary package PyQtWebengine. Means when I try to run my application, I receive the error message, that PyQtWebengine package/module is not installed which Im not able to install with pip. So I uninstalled it.
Installed sip and uninstalled
qt (6.2.2) and qt#5 (5.15.2) are installed with brew
Run cmd: python3 -m pip install PyQt5
Pip is up to date (21.3.1)
pip install with a specific PyQt5 Version
Any ideas to solve this problem?
Thanks in advance for any ideas/solutions!

The way I solved the same problem in my M1s was installing the library via terminal launched in Rosetta mode (left click on the Terminal icon -> Get Info -> Open in Rosetta).
So, detailed steps are:
Open a Terminal with Rosetta 2 via left click on the Terminal icon -> Get Info -> Open in Rosetta (https://dev.to/courier/tips-and-tricks-to-setup-your-apple-m1-for-development-547g)
Use non-homebrew python (mine was in /usr/bin/python3) to create virtual environment
$ /usr/bin/python3 -m venv venv
$ source venv/bin/activate
Upgrade pip
(venv)$ pip install --upgrade pip
Install PyQt5
(venv) $pip install PyQt5
Alternatively, you can do a one-off installation via this command:
$ arch -x86_64 python -m pip install PyQt5

I use macos 12.1 (m1), and I use mini-forge with homebrew, I have installed pyqt5 with conda install pyqt.
P.S. my python version is 3.9.

conda create -n py3.9.13 python=3.9.13
conda install pyqt
Worked for me. I'm using macOS Monterey 12.4, with the Apple M1 chip. Anaconda3 installed many dependences automatically while installing. After the above installation, my conda list:
# Name Version
bzip2 1.0.8
ca-certificates 2022.6.15
gettext 0.19.8.1
glib 2.70.2
glib-tools 2.70.2
gst-plugins-base 1.20.3
gstreamer 1.20.3
icu 70.1
jpeg 9e
krb5 1.19.3
libclang 14.0.6
libclang13 14.0.6
libcxx 14.0.6
libedit 3.1.20191231
libffi 3.4.2
libglib 2.70.2
libiconv 1.16
libllvm14 14.0.6
libogg 1.3.4
libopus 1.3.1
libpng 1.6.37
libpq 14.4
libvorbis 1.3.7
libzlib 1.2.12
lz4-c 1.9.3
mysql-common 8.0.29
mysql-libs 8.0.29
ncurses 6.3
nspr 4.32
nss 3.78
openssl 1.1.1p
packaging 21.3
pcre 8.45
pip 22.1.2
ply 3.11
pyparsing 3.0.9
pyqt 5.15.4
pyqt5-sip 12.9.0
python 3.9.13
python_abi 3.9
qt-main 5.15.4
readline 8.1.2
setuptools 62.6.0
sip 6.6.2
sqlite 3.39.0
tk 8.6.12
toml 0.10.2
tzdata 2022a
wheel 0.37.1
xz 5.2.5
zlib 1.2.12
zstd 1.5.2

As I answered here, Rosetta is not required if you're willing to use Homebrew's pyqt#5. Homebrew includes an arm64-compiled pyqt5, and one can leverage its installation in a venv using the --system-site-packages flag to venv:
$ # Install pyqt5 via homebrew
$ brew install pyqt#5
$ # Note that it's installed in python3.9, not 3.10
$ brew cat pyqt#5 | grep 'depends_on.*python'
depends_on "python#3.9"
$ # Make a python3.9 virtualenv with access to the system's site-packages
$ /opt/homebrew/bin/python3.9 -m venv --system-site-packages .venv
$ source .venv/bin/activate

Related

Tried to install PyQt5-tools via pip, didn't work [duplicate]

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

AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel' for PyQt5 5.15.0

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

Spyder: importerror: cannot import name constants

Ubuntu 16.04
Python 2.7
Anaconda 2
I have Anaconda2 installed. This includes the spyder IDE, according to google.
$ spyder
Gives:
Traceback (most recent call last):
File "/home/username/anaconda2/bin/spyder", line 7, in <module>
from spyder.app.start import main
File "/home/username/anaconda2/lib/python2.7/site-packages/spyder/app/start.py", line 13, in <module>
import zmq
File "/usr/lib/python2.7/dist-packages/zmq/__init__.py", line 66, in <module>
from zmq import backend
File "/usr/lib/python2.7/dist-packages/zmq/backend/__init__.py", line 40, in <module>
reraise(*exc_info)
File "/usr/lib/python2.7/dist-packages/zmq/backend/__init__.py", line 27, in <module>
_ns = select_backend(first)
File "/usr/lib/python2.7/dist-packages/zmq/backend/select.py", line 27, in select_backend
mod = __import__(name, fromlist=public_api)
File "/usr/lib/python2.7/dist-packages/zmq/backend/cython/__init__.py", line 6, in <module>
from . import (constants, error, message, context,
ImportError: cannot import name constants
Doesn't work:
$ sudo apt-get purge spyder
$ sudo apt-get install spyder
Doesn't work:
$ conda uninstall spyder
$ conda install spyder
Googling the error doesn't help me along. I'm not a programmer. Python libraries and Anaconda directories and IDE repositories, are all Greek to me. Might be useful information for those who actually know how things work: importing scipy.io also gives me importerrors.
Where is the fault and how do I resolve it?
EDITS
$ conda update chardet
gives:
/home/pieter/anaconda2/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.3.0) doesn't match a supported version!
RequestsDependencyWarning)
Solving environment: done
# All requested packages already installed.
and
$ conda update urllib3
gives:
/home/pieter/anaconda2/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.3.0) doesn't match a supported version!
RequestsDependencyWarning)
Solving environment: done
# All requested packages already installed.
$ conda info spyder
gives:
absurdly long, long, long list of replies
of which the last is:
spyder 3.2.4 py27h04a3490_0
---------------------------
file name : spyder-3.2.4-py27h04a3490_0.tar.bz2
name : spyder
version : 3.2.4
build string: py27h04a3490_0
build number: 0
channel : https://repo.continuum.io/pkgs/main/linux-64
size : 2.5 MB
arch : None
constrains : ()
license : MIT
md5 : ed9729850ec1ab3c83d87b422e687bc5
platform : None
subdir : linux-64
timestamp : 1508356637551
url : https://repo.continuum.io/pkgs/main/linux-64/spyder-3.2.4-py27h04a3490_0.tar.bz2
dependencies:
chardet >=2.0
jedi >=0.9
nbconvert
numpydoc
pickleshare
psutil
pycodestyle
pyflakes
pygments >=2.0
pylint
pyqt
python >=2.7,<2.8.0a0
pyzmq
qtawesome >=0.4.1
qtconsole >=4.2
qtpy >=1.2.0
rope >=0.9.4
sphinx
myEnv:
(myEnv) pieter#t:~/bagfile_analysis$ spyder
Traceback (most recent call last):
File "/home/pieter/anaconda2/envs/myEnv/bin/spyder", line 4, in <module>
import re
File "/home/pieter/anaconda2/envs/myEnv/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
Hmmm... have you tried THIS already?
Also, how exactly did you install spyder? Maybe you didn't install it in the right environemnt(in your case probably the default root/base environment)
I'd recommend installing it via conda in the terminal! Also make sure you have installed it in the right environment:
get a list of all your environments:
$ conda env list
install it in a specific environment:
$ conda install --name "your env" spyder
and of course make sure you got the latest anaconda version:
$ conda update -n base conda
EDIT
ok now we know you only have your base environment.
since chardet is a dependency of spyder let's update those two packages first to be sure...
$ conda update chardet
$ conda update urllib3
Let's go on and check your spyder.
Does it work now?
if not try this:
$ conda info spyder
what do you get?
you should get a very long list, but only the last entry is of importance, something like that:
spyder 3.2.5 py27_0
-------------------
file name : spyder-3.2.5-py27_0.tar.bz2
name : spyder
version : 3.2.5
build string: py27_0
build number: 0
channel : https://repo.continuum.io/pkgs/main/osx-64
size : 2.5 MB
arch : None
constrains : ()
license : MIT
md5 : 5ec8ffcda103c23c81005a5aed0c91e7
platform : None
subdir : osx-64
timestamp : 1514270782022
url : https://repo.continuum.io/pkgs/main/osx-64/spyder-3.2.5-py27_0.tar.bz2
dependencies:
chardet >=2.0
cloudpickle
jedi >=0.9
nbconvert
numpydoc
pickleshare
psutil
pycodestyle
pyflakes
pygments >=2.0
pylint
pyqt
python >=2.7,<2.8.0a0
python.app
pyzmq
qtawesome >=0.4.1
qtconsole >=4.2
qtpy >=1.2.0
rope >=0.9.4
sphinx
if you don't get anything back you have installed spyder in the wrong environment and you can skip step 1:
STEP 1:
uninstall spyder again.
$ conda uninstall spyder
STEP 2:
reinstall it
$ conda install spyder
EDIT II
Have you had a look at the link I posted?
the only other thing that comes is in my mind is trying a different environment (for example called "myEnv").
$ conda create --name myEnv spyder
then activate the environment and try to launch spyder. conda tells you how to activate the environment, but i guess it's the same as for mac os:
$ source activate myEnv
$ spyder
$ source deactivate
if that doesn't work you can remove the environment again.
$ conda remove --name myEnv *
In any case the dependency error is weird...

using GTKAgg backend on python 3.5 (anaconda) and centos 7

I tried to use GTKAgg as back-end for matplotlib package.
matplotlib.use('GTKAgg')
Failed to enable GUI event loop integration for 'gtk'
Traceback (most recent call last):
File "/home/oshri/.pycharm_helpers/pydev/_pydev_bundle/pydev_console_utils.py", line 569, in do_enable_gui
enable_gui(guiname)
File "/home/oshri/.pycharm_helpers/pydev/pydev_ipython/inputhook.py", line 528, in enable_gui
return gui_hook(app)
File "/home/oshri/.pycharm_helpers/pydev/pydev_ipython/inputhook.py", line 244, in enable_gtk
from pydev_ipython.inputhookgtk import create_inputhook_gtk
File "/home/oshri/.pycharm_helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/home/oshri/.pycharm_helpers/pydev/pydev_ipython/inputhookgtk.py", line 19, in <module>
import gtk, gobject # #UnresolvedImport
File "/home/oshri/.pycharm_helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named 'gtk'
I tried to install the gtk using conda, using this repo, the conda outputs that the package is installed.
import conda.cli
conda.cli.main('conda','install','-c','ska','pygtk=2.16.0')
Fetching package metadata .............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at /data/anaconda:
#
pygtk 2.16.0 0 ska
When I tried to install the pygtk using pip I got this error.
[oshri#analytics ~]$ pip install pygtk
Collecting pygtk
Using cached pygtk-2.24.0.tar.bz2
Complete output from command python setup.py egg_info:
********************************************************************
* Building PyGTK using distutils is only supported on windows. *
* To build PyGTK in a supported way, read the INSTALL file. *
********************************************************************
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-x78h7u1k/pygtk/
When I tried to use python2.7 I success to import the model.
[oshri#analytics ~]$ /bin/python2.7
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygtk
>>> exit()
For this reason I think that the issue is related to the python version.
I tried to use this guide but I didn't succeed to use JHBuild.
[oshri#analytics ~]$ jhbuild build pygobject
Required packages:
System installed packages which are too old:
(none)
No matching system package installed:
itstool
libffi (libffi.pc, required=3.0.0)
python3-devel (python3.pc, required=3.2)
libxslt (libxslt.pc, required=1.1.26)
cairo (cairo.pc, required=1.14.0)
libxml2 (libxml-2.0.pc, required=2.7.8)
jhbuild build: Required system dependencies not installed. Install using the command 'jhbuild sysdeps --install' or to ignore system dependencies use command-line option --nodeps
[oshri#analytics ~]$ jhbuild build sysdeps --install pygobject
Usage: jhbuild build [ options ... ] [ modules ... ]
jhbuild: error: no such option: --install
[oshri#analytics ~]$ jhbuild sysdeps --install pygobject
System installed packages which are new enough:
zlib (zlib.pc, installed=1.2.7)
automake
docbook-xml
docbook-xsl
libtool
pkg-config
cc
make
git
xmlcatalog
bison (required=2.4)
intltool (required=0.50.2)
xmllint
xsltproc
libpcre (libpcre.pc, required=8.31, installed=8.32)
flex (required=2.0)
Required packages:
System installed packages which are too old:
(none)
No matching system package installed:
itstool
libxml2 (libxml-2.0.pc, required=2.7.8)
libxslt (libxslt.pc, required=1.1.26)
cairo (cairo.pc, required=1.14.0)
libffi (libffi.pc, required=3.0.0)
python3-devel (python3.pc, required=3.2)
Optional packages: (JHBuild will build the missing packages)
System installed packages which are too old:
(none)
No matching system package installed:
I: Installing dependencies on system: itstool libxml2 libxslt cairo libffi python3-devel
I: Computing packages to install. This might be slow. Please wait.
I: Installing:
itstool;1.2.0-4.el7;noarch;base
libffi-devel;3.0.13-18.el7;x86_64;base
python34-devel;3.4.5-4.el7;x86_64;epel
cairo-devel;1.14.2-1.el7;x86_64;base
libxml2-devel;2.9.1-6.0.1.el7_2.3;x86_64;ol7_latest
libxslt-devel;1.1.28-5.0.1.el7;x86_64;ol7_latest
I: This might take a very long time. Do not turn off your computer. You can run `pkmon' to monitor progress.
E: PackageKit: Failed to obtain authentication.
I: Complete!
[oshri#analytics ~]$ sudo jhbuild sysdeps --install pygobject
[sudo] password for oshri:
sudo: jhbuild: command not found
I'm right that issues related to python version?
Should I install JHBuild under root user?

"AssertionError: Only python 2.7 and later is supported by ptyprocess", when installing pexpect via pip on python 2.6

I got following error when trying install pexpect via pip:
# pip install pexpect
Collecting pexpect
do_ypcall: clnt_call: RPC: Unable to receive; errno = Connection refused
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Using cached pexpect-4.0.tar.gz
Collecting ptyprocess>=0.5 (from pexpect)
Using cached ptyprocess-0.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/tmp/pip-build-2X4It7/ptyprocess/setup.py", line 10, in <module>
"Only python 2.7 and later is supported by ptyprocess.")
AssertionError: Only python 2.7 and later is supported by ptyprocess.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-2X4It7/ptyprocess
It's pretty clear that downloaded ptyprocess works only with python 2.7, but doesn't pip should download correct packages versions, that are compatible with installed python versions?
My system info:
pip -V: pip 7.1.2 from /usr/lib/python2.6/site-packages (python 2.6)
python -V: Python 2.6.6
OS: CentOS 6.3
BTW: yum install pexpect succesfully installs pexpect package
Thank You
yum will install pexpect v2.3.6.
easy_install or pip will install pexpect v4.0.1 as of today.
You can use pexpect version 3.3 which not depends on ptyprocess version.
# easy_install pexpect==3.3
or
# pip install pexpect==3.3
AssertionError: Only python 2.7 and later is supported by ptyprocess.
pyexpect depends on ptyprocess>=0.5 (https://github.com/pexpect/pexpect/blob/master/setup.py#L66)
You will need to install a version of ptyprocess that is >=0.5 but works with python 2.6 first, then install pyexpect.
edit looks like you are out of luck, 0.5 requires python 2.7 (https://github.com/pexpect/ptyprocess/blob/master/setup.py#L9-L10). Your system package has it patched to work with 2.6 so you'll have to use that.

Categories