简体   繁体   English

如何使用python 2.7在Ubuntu 12.04上安装PyQt?

[英]How to install PyQt on Ubuntu 12.04 with python 2.7?

There may be some similar questions like this one , but I didn't find any answer for me. 有可能是像一些类似的问题这一个 ,但我没有找到任何回答我。

I tried some ways to do it like: 我尝试了一些方法来做到:

sudo aptitude install python-qt4-dev python-sip4 python-sip4-dev

from: https://groups.google.com/forum/#!topic/mnemosyne-proj-devel/VQQzjhARWoA 来自: https//groups.google.com/forum/#!topic/mnemosyne-proj-devel/VQQzjhARWoA

I tried: 我试过了:

sudo aptitude install python-qt4

from: http://www.saltycrane.com/blog/2008/01/how-to-install-pyqt4-on-ubuntu-linux/ 来自: http//www.saltycrane.com/blog/2008/01/how-to-install-pyqt4-on-ubuntu-linux/

Every time after above installations I got error: 每次上述安装后我都会收到错误:

$python2.7
Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] 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

I also tried to install it from source downloading PyQt4 from: http://www.riverbankcomputing.co.uk/software/pyqt/download and sip from: http://www.riverbankcomputing.co.uk/software/sip/download 我还试图从源代码下载PyQt4安装它: http ://www.riverbankcomputing.co.uk/software/pyqt/download并从以下网址获取: http//www.riverbankcomputing.co.uk/software/sip/download

Then I got error tring to install PyQt4: 然后我得到安装PyQt4的错误:

$ sudo python configure.py --verbose
Determining the layout of your Qt installation...
/usr/bin/qmake -o qtdirs.mk qtdirs.pro
make -f qtdirs.mk
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -o qtdirs.o qtdirs.cpp
qtdirs.cpp:1:28: fatal error: QCoreApplication: No such file or directory
compilation terminated.
make: *** [qtdirs.o] Error 1
Error: Failed to determine the layout of your Qt installation. Try again using
the --verbose flag to see more detail about the problem.

My question is: What is proper and effective way to install PyQt4 on Ubuntu 12.04? 我的问题是:在Ubuntu 12.04上安装PyQt4的正确有效方法是什么?

You did in fact properly install the python bindings for Qt4 when you used: 实际上,当您使用时,您确实正确安装了Qt4的python绑定:

sudo aptitude install python-qt4

You should usually use the Distribution-provided packages - the Ubuntu-provided packages are perfectly adequate for your needs. 您通常应该使用Distribution提供的软件包 - Ubuntu提供的软件包完全可以满足您的需求。

What's puzzling me is the error you got after installing the Ubuntu package. 令我困惑的是你在安装Ubuntu软件包后遇到的错误。 I just tried this on a Ubuntu 12.04 installation and it worked for me. 我刚刚在Ubuntu 12.04安装上试过它,它对我有用。 That suggests to me that your current installation of Ubuntu on your system is broken in some way. 这告诉我你的系统上当前安装的Ubuntu在某种程度上被打破了。

You could try completely purging the python-qt4 package and reinstalling it again; 您可以尝试完全清除python-qt4包并重新安装它;

sudo apt-get remove --purge python-qt4

If you also issue: 如果您还发出:

sudo apt-get clean

... that will remove any downloaded package files from the system, so that apt will then download the package file again when you issue a ...将从系统中删除任何下载的包文件,以便apt在您发出时再次下载包文件

sudo apt-get install python-qt4

If that still doesn't work, then something very odd indeed is going on with your Ubuntu installation, and it might be wise to completely reinstall Ubuntu. 如果这仍然不起作用,那么你的Ubuntu安装确实会发生一些非常奇怪的事情,完全重新安装Ubuntu可能是明智之举。

On aws ubuntu (12.04 and 14.04): 在aws ubuntu(12.04和14.04):

sudo apt-get update
sudo apt-get install python-qt4
sudo apt-get install libxml2-dev libxslt1-dev python-dev
sudo apt-get install python-lxml
sudo apt-get install xvfb

Check this link and generate your-own-example.py 检查此链接并生成your-own-example.py

DISPLAY=localhost:1.0 xvfb-run python your-own-example.py

Voila. 瞧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM