是否可以在 Virtualenv 沙箱上添加 PyQt4/PySide 包?
我在我的开发环境中使用 Virtualenv 并通过 web.py
、simplejson
和其他面向 Web 的包。
我将使用 Qt 开发一个简单的 python 客户端,以重用一些使用 web.py 开发的 Api。
这里有人用 Virtualenv 成功安装了 PyQt4 吗?
是否可以?
我已经下载了所有二进制文件,并在我的 python2.6 目录中全局安装了 PyQt4
。
如果我不使用 --no-site--packages
选项,Virtualenv 会在我的新沙箱中正确包含 PyQt4
,但显然,包含我不使用的所有全局包不需要。
有没有一种干净的方法可以使用 --no-site--packages
选项准备新的沙箱,然后使用 添加
、PyQt4
或 PySide
>pipeasy_install
还是其他一些魔术?
I'm using Virtualenv with profit on my development environment with web.py
, simplejson
and other web oriented packages.
I'm going to develop a simple python client using Qt to reuse some Api developed with web.py.
Does anybody here had succesfully installed PyQt4 with Virtualenv?
Is it possible?
I've downloaded all the binaries and have PyQt4
installed globally on my python2.6 directory.
If I don't use --no-site--packages
option, Virtualenv correctly includes PyQt4
in my new sandbox but, obviously, with all the global packages that I don't need.
Is there a clean way to prepare a new sandbox with --no-site--packages
option and then add PyQt4
or PySide
using pip
, easy_install
or some other magic trick?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
创建一个空的 virtualenv 就足够了,然后将
.../site-packages/PyQt4
目录的内容复制到其中。我建议全局安装 PyQt4 一次,复制目录,卸载它,然后使用这个技巧来创建 VE。
It should be enough to create an empty virtualenv and then copy the contents of the
.../site-packages/PyQt4
directories into it.I suggest to install PyQt4 once globally, make a copy of the directory, uninstall it and then use this trick to create VEs.
我有同样的问题。我使用 virtualenvwrapper,所以我编写了这个脚本来在每个新的虚拟环境中创建到 PyQt 的链接。也许对其他人有用:
链接到要点
I have the same problem. I use virtualenvwrapper, so I wrote this script to create a link to PyQt in every new virtual environment. Maybe is useful for someone else:
link to gist
Linux debian,python 2.7:
ln -s /usr/lib/ python2.7/dist-packages/sip.so ~/.virtualenvs/myEnv/lib/python2.7/site-packages/
Linux debian, python 2.7:
sudo apt-get install python-qt4
ln -s /usr/lib/python2.7/dist-packages/PyQt4/ ~/.virtualenvs/myEnv/lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/sip.so ~/.virtualenvs/myEnv/lib/python2.7/site-packages/
对于那些想要在 Python 3 virtualenv(在 OSX 上)中使用 PyQt4 的人,您首先安装 PyQt4 和 SIP(我将使用自制软件)
然后创建您的虚拟环境
最后符号链接(更改安装在您的设备上的 SIP、PyQt4 和 Python 的版本)机器)
For those who want to use PyQt4 in a Python 3 virtualenv (on OSX) you first install PyQt4 and SIP (I will use homebrew)
Then create your virtual environment
Finally symlink (change the versions of SIP, PyQt4 and Python for those installed on your machine)
我询问是否可以在 irc.freenode.net #pyside 频道上的 virtualenv 中安装 PySide,并从 hugopl 得到了肯定的答复。因此,我按照 PySide Binaries for Microsoft Windows 的说明进行操作,结果成功了。输出如下。
I asked if it's possible to install PySide from within virtualenv on irc.freenode.net #pyside channel and got positive answer from hugopl. So I followed instructions from PySide Binaries for Microsoft Windows and it worked. The output is below.
假设您的 virtualenv 名为 myProject 并且您正在使用 virtualenvwrapper。还假设有 Unix 平台。
Let's assume your virtualenv is named myProject and you're using virtualenvwrapper. A Unix platform is also assumed.
最简单的方法是安装这个: vext.pyqt4
这将添加单个系统
PyQt4
打包到你的 virtualenv 中。Ubuntu 16.04 使用方法:
Easiest way is to install this : vext.pyqt4
This will add the single system
PyQt4
package to your virtualenv.Ubuntu 16.04 usage:
对于 PySide 1.2.1 和 Ubuntu 12.4
安装编译器、Qt 相关的 python 源
使用
virtualenvwrapper
创建 virt env准备编译 Qt(约 30 分钟)
测试
For PySide 1.2.1 and Ubuntu 12.4
Install compilers, Qt related, python sources
Create virt env with
virtualenvwrapper
Be ready for compiling Qt (~30 min)
Test
如果您在 Mac 上通过 brew 安装了 pyqt(特别是我在 Mavericks 上):
当然,这些版本文件夹编号可能会随着时间的推移而改变。
If you installed pyqt via brew on a Mac (specifically I'm on Mavericks):
Of course those version folder numbers may change over time.
对我有用的是从
/usr/lib/python2.7/dist-packages< 复制
/PyQt4/
和sip.x86_64-linux-gnu.so
/code> 到/lib/python2.7/site-packages
并更改这些复制文件的所有权权限(因为副本由 root 拥有)。What worked for me was copying
/PyQt4/
andsip.x86_64-linux-gnu.so
from/usr/lib/python2.7/dist-packages
to<VIRTUALENV>/lib/python2.7/site-packages
and changing the ownership permissions on these copied files (since the copies were owned by root).扩展 Aaron Digulla 的答案,使用 git 获取正确的文件列表非常方便。我通常会做这样的事情(从 msysGit shell):
然后运行 PyQt4(或其他)的安装程序。之后,制作安装程序添加的文件的 tarball 并删除临时 git 存储库,如下所示:
然后您可以运行 PyQt4 的卸载程序(如果您不想弄乱您的系统 Python),然后简单地解压
pyqt4.tar.bz2
到您的 virtualenv 文件夹中。如果您已经习惯使用 git,这是确保您获得 PyQt4 安装的所有文件的好方法。注意:使用打包的安装程序安装 PyQt4 也会安装 SIP。如果您确实想要使用此 SIP 在 virtualenv 中为您自己的 C/C++ 代码创建绑定,则需要修改
sipconfig.py
文件中的路径复制过来之后。否则,SIP 的构建系统仍将指向系统 Python 文件夹(例如,C:\Python32
或其他),如果您从那里删除所有 PyQt4 安装的文件,则该文件夹将不起作用。 (如果您无意自己使用 SIP,则可以跳过此步骤。)Expanding on Aaron Digulla's answer, using git to get the file list right can be really handy. I usually do something like this (from an msysGit shell):
Then run the installer for PyQt4 (or whatever). After that, make a tarball of the files that the installer added and delete the temp git repo, as follows:
Then you can run PyQt4's uninstaller (if you don't want to clutter up your system Python), and simply untar
pyqt4.tar.bz2
into your virtualenv folder. If you're already comfortable using git, this is a great way to ensure you get all the PyQt4-installed files.NOTE: Installing PyQt4 using the packaged installer also installs SIP. If you actually want to use this SIP to create bindings for your own C/C++ code inside your virtualenv, you'll want to modify the paths in the
sipconfig.py
file after you copy it over. Otherwise, SIP's build system will still be pointing at the system Python folder (e.g.,C:\Python32
or whatever), which won't work if you delete all the PyQt4-installed files from there. (If you don't have any intention of using SIP yourself, you can probably skip this.)符号链接可能有效。
我使用 Linux (Debian/sid)、python 3.4、PySide、virtualenv 和 PyCharm (IDE),但这些相同的指令适用于任何包和开发环境。
/usr/lib/python3/dist-packages/PySide/
$VIRTUAL_ENV/lib/python3.4/site-packages/PySide/
之间的符号链接对我有用。有趣的是,如果我仅符号链接
PySide
目录,则它不起作用。我需要对目录中的每个文件进行符号链接。这可能是 PyCharm(我的 IDE)的限制——我不知道。Symbolic links may work.
I use Linux (Debian/sid), python 3.4, PySide, virtualenv, and PyCharm (IDE), but these same instructions will work for any package and development environment.
Symbolic links between
/usr/lib/python3/dist-packages/PySide/
$VIRTUAL_ENV/lib/python3.4/site-packages/PySide/
work for me.Interestingly, if I symbolic link only the
PySide
directory, it does not work. I need to symlink each file within the directory. That may be a limitation of PyCharm (my IDE) -- I don't know.试试这个:
pip 安装 python-qt5
Try this one:
pip install python-qt5