Python 2.7 ne peut pas importer PyQt4
-
25-09-2019 - |
Question
Je l'ai mis à jour à Python 2.7 de Python 2.6 sur Ubuntu Maverick Meerkat (10,10) et je ne parviens pas à importer PyQt4.
austin@gerald:~$ python2.7
Python 2.7.0+ (r27:82500, Sep 15 2010, 18:04:55)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4
J'ai installé à la fois Python 2.7 (python2.7) et PyQt4 (python-Qt4) à partir des dépôts Ubuntu. Je l'ai installé PyQt un certain temps, mais j'ai installé Python 2.7 récemment.
Si je tente Python 2.6 (car il est livré avec Ubuntu, la commande est simplement python ), il fonctionne parfaitement. Regardez:
austin@gerald:~$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt4
Je sais ce que le problème est: les modules PyQt4 sont accessibles par Python 2.6 mais pas 2.7. Ma question est, comment puis-je obtenir Python 2.7 pour trouver le module PyQt4 (s)? Aide!
Note:. Désolé si cela appartient à Super User, je programmais juste au moment où j'ai rencontré ce problème
La solution
Dans le système Ubuntu, vous pouvez l'installer via apt-get
apt-get install python-qt4
Autres conseils
PyQt n'utilise pas setup.py il ne peut pas être installé à l'aide pip ou easy_install
Ici vous avez un tutoriel montrant comment construire et installer PyQt pour python2.7:
http: //problemssol.blogspot .com / 2010/12 / compilation et install-pyqt4-pour-python27.html
Mise à jour: Pour Ubuntu 12.04+ il suffit d'utiliser apt-get:
apt-get install python-qt4
Mac OS X 10.8.2 testé:
sudo pip install SIP
got IOError: [Errno 2] Aucun fichier ou répertoire: '/tmp/pip-build/SIP/setup.py'
Il est ok alors:
cd /tmp/pip-build/SIP
sudo python configure.py
make
sudo make install
télécharger PyQt à partir de: http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.9.6/PyQt-mac-gpl-4.9.6.tar.gz
décompressez.
cd PyQt-mac-gpl-4.9.6
sudo python configure.py
make
il faudra un certain temps, après faire alors:
sudo make install
Profitez:)
Vous pouvez télécharger une version de PyQt4 ici pour une version de Python, mais depuis que vous avez demandé Python 2.7, voici le lien pour le téléchargement de python 2.7:
https://sourceforge.net/projects/pyqt/files /PyQt4/PyQt-4.11.4/
Vous devez installer PyQt4 dans l'environnement Python 2.7. Pour ce faire, exécutez
easy_install2.7 PyQt4
Si easy_install n'est pas installé, vous devez d'abord télécharger et l'installer en exécutant
python2.7 setup.py install
S'il vous plaît installer les outils premier module SIP, ce python est et c / c ++ lib, et PyQt4 lib