是否可以在 Virtualenv 沙箱上添加 PyQt4/PySide 包?

发布于 2024-08-16 19:10:14 字数 616 浏览 5 评论 0原文

我在我的开发环境中使用 Virtualenv 并通过 web.pysimplejson 和其他面向 Web 的包。
我将使用 Qt 开发一个简单的 python 客户端,以重用一些使用 web.py 开发的 Api。

这里有人用 Virtualenv 成功安装了 PyQt4 吗?
是否可以?

我已经下载了所有二进制文件,并在我的 python2.6 目录中全局安装了 PyQt4
如果我不使用 --no-site--packages 选项,Virtualenv 会在我的新沙箱中正确包含 PyQt4 ,但显然,包含我不使用的所有全局包不需要。

有没有一种干净的方法可以使用 --no-site--packages 选项准备新的沙箱,然后使用 添加 PyQt4PySide >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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

追风人 2024-08-23 19:10:14

创建一个空的 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.

云之铃。 2024-08-23 19:10:14

我有同样的问题。我使用 virtualenvwrapper,所以我编写了这个脚本来在每个新的虚拟环境中创建到 PyQt 的链接。也许对其他人有用:

#!/bin/bash
# This hook is run after a new virtualenv is activated.
# ~/.virtualenvs/postmkvirtualenv

LIBS=( PyQt4 sip.so )

PYTHON_VERSION=python$(python -c "import sys; print (str(sys.version_info[0])+'.'+str(sys.version_info[1]))")
VAR=( $(which -a $PYTHON_VERSION) )

GET_PYTHON_LIB_CMD="from distutils.sysconfig import get_python_lib; print (get_python_lib())"
LIB_VIRTUALENV_PATH=$(python -c "$GET_PYTHON_LIB_CMD")
LIB_SYSTEM_PATH=$(${VAR[-1]} -c "$GET_PYTHON_LIB_CMD")

for LIB in ${LIBS[@]}
do
    ln -s $LIB_SYSTEM_PATH/$LIB $LIB_VIRTUALENV_PATH/$LIB 
done

链接到要点

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:

#!/bin/bash
# This hook is run after a new virtualenv is activated.
# ~/.virtualenvs/postmkvirtualenv

LIBS=( PyQt4 sip.so )

PYTHON_VERSION=python$(python -c "import sys; print (str(sys.version_info[0])+'.'+str(sys.version_info[1]))")
VAR=( $(which -a $PYTHON_VERSION) )

GET_PYTHON_LIB_CMD="from distutils.sysconfig import get_python_lib; print (get_python_lib())"
LIB_VIRTUALENV_PATH=$(python -c "$GET_PYTHON_LIB_CMD")
LIB_SYSTEM_PATH=$(${VAR[-1]} -c "$GET_PYTHON_LIB_CMD")

for LIB in ${LIBS[@]}
do
    ln -s $LIB_SYSTEM_PATH/$LIB $LIB_VIRTUALENV_PATH/$LIB 
done

link to gist

热血少△年 2024-08-23 19:10:14

Linux debian,python 2.7:

  • 全局安装 python-qt4: sudo apt-get install python-qt4
  • 创建 PyQt4 到虚拟环境的符号链接 ln -s /usr/lib/python2.7 /dist-packages/PyQt4/ ~/.virtualenvs/myEnv/lib/python2.7/site-packages/
  • 创建 sip.so 到虚拟环境的符号链接ln -s /usr/lib/ python2.7/dist-packages/sip.so ~/.virtualenvs/myEnv/lib/python2.7/site-packages/

Linux debian, python 2.7:

  • Install python-qt4 globaly: sudo apt-get install python-qt4
  • Create symbolic link of PyQt4 to your virtual env ln -s /usr/lib/python2.7/dist-packages/PyQt4/ ~/.virtualenvs/myEnv/lib/python2.7/site-packages/
  • Create symbolic link of sip.so to your virtual envln -s /usr/lib/python2.7/dist-packages/sip.so ~/.virtualenvs/myEnv/lib/python2.7/site-packages/
顾北清歌寒 2024-08-23 19:10:14

对于那些想要在 Python 3 virtualenv(在 OSX 上)中使用 PyQt4 的人,您首先安装 PyQt4 和 SIP(​​我将使用自制软件)

$ brew install python3
$ brew install sip --with-python3
$ brew install pyqt --with-python3

然后创建您的虚拟环境

$ virtualenv ...

最后符号链接(更改安装在您的设备上的 SIP、PyQt4 和 Python 的版本)机器)

$ ln -s /usr/local/Cellar/sip/4.15.5/lib/python3.4/site-packages/*.* ~/{VIRTUALENVHOME}/{VIRTUALENVNAME}/lib/python3.4/site-packages/
$ ln -s /usr/local/Cellar/pyqt/4.10.4/lib/python3.4/site-packages/PyQt4/*.* ~/{VIRTUALENVHOME}/{VIRTUALENVNAME}/lib/python3.4/site-packages/PyQt4

For those who want to use PyQt4 in a Python 3 virtualenv (on OSX) you first install PyQt4 and SIP (I will use homebrew)

$ brew install python3
$ brew install sip --with-python3
$ brew install pyqt --with-python3

Then create your virtual environment

$ virtualenv ...

Finally symlink (change the versions of SIP, PyQt4 and Python for those installed on your machine)

$ ln -s /usr/local/Cellar/sip/4.15.5/lib/python3.4/site-packages/*.* ~/{VIRTUALENVHOME}/{VIRTUALENVNAME}/lib/python3.4/site-packages/
$ ln -s /usr/local/Cellar/pyqt/4.10.4/lib/python3.4/site-packages/PyQt4/*.* ~/{VIRTUALENVHOME}/{VIRTUALENVNAME}/lib/python3.4/site-packages/PyQt4
鹿童谣 2024-08-23 19:10:14

我询问是否可以在 irc.freenode.net #pyside 频道上的 virtualenv 中安装 PySide,并从 hugopl 得到了肯定的答复。因此,我按照 PySide Binaries for Microsoft Windows 的说明进行操作,结果成功了。输出如下。

Z:\virtualenv\pyside>Scripts\activate.bat

(pyside) Z:\virtualenv\pyside>where python
Z:\virtualenv\pyside\Scripts\python.exe

(pyside) Z:\virtualenv\pyside>easy_install PySide
install_dir Z:\virtualenv\pyside\Lib\site-packages\
Searching for PySide
Reading http://pypi.python.org/simple/PySide/
Reading http://www.pyside.org
Reading http://www.pyside.org/files/pkg/
Best match: PySide 1.0.0beta1qt471
Downloading http://www.pyside.org/files/pkg/PySide-1.0.0beta1qt471.win32-py2.6.exe
Processing PySide-1.0.0beta1qt471.win32-py2.6.exe
Deleting c:\users\piotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg.tmp\EGG-INFO\scripts\py
ide-uic-script.py
Deleting c:\users\piotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg.tmp\EGG-INFO\scripts\py
ide-uic.exe
creating 'c:\users\piotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg' and adding 'c:\users\
iotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg.tmp' to it
creating z:\virtualenv\pyside\lib\site-packages\PySide-1.0.0beta1qt471-py2.6-win32.egg
Extracting PySide-1.0.0beta1qt471-py2.6-win32.egg to z:\virtualenv\pyside\lib\site-packages
Adding PySide 1.0.0beta1qt471 to easy-install.pth file
Installing pyside-uic-script.pyc script to Z:\virtualenv\pyside\Scripts
Installing pyside_postinstall.py script to Z:\virtualenv\pyside\Scripts
Installing pyside_postinstall.pyc script to Z:\virtualenv\pyside\Scripts
Installing pyside-uic-script.py script to Z:\virtualenv\pyside\Scripts
Installing pyside-uic.exe script to Z:\virtualenv\pyside\Scripts

Installed z:\virtualenv\pyside\lib\site-packages\pyside-1.0.0beta1qt471-py2.6-win32.egg
Processing dependencies for PySide
Finished processing dependencies for PySide

(pyside) Z:\virtualenv\pyside>python Scripts\pyside_postinstall.py -install
Generating file Z:\virtualenv\pyside\Scripts\qt.conf...
The PySide extensions were successfully installed.

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.

Z:\virtualenv\pyside>Scripts\activate.bat

(pyside) Z:\virtualenv\pyside>where python
Z:\virtualenv\pyside\Scripts\python.exe

(pyside) Z:\virtualenv\pyside>easy_install PySide
install_dir Z:\virtualenv\pyside\Lib\site-packages\
Searching for PySide
Reading http://pypi.python.org/simple/PySide/
Reading http://www.pyside.org
Reading http://www.pyside.org/files/pkg/
Best match: PySide 1.0.0beta1qt471
Downloading http://www.pyside.org/files/pkg/PySide-1.0.0beta1qt471.win32-py2.6.exe
Processing PySide-1.0.0beta1qt471.win32-py2.6.exe
Deleting c:\users\piotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg.tmp\EGG-INFO\scripts\py
ide-uic-script.py
Deleting c:\users\piotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg.tmp\EGG-INFO\scripts\py
ide-uic.exe
creating 'c:\users\piotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg' and adding 'c:\users\
iotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg.tmp' to it
creating z:\virtualenv\pyside\lib\site-packages\PySide-1.0.0beta1qt471-py2.6-win32.egg
Extracting PySide-1.0.0beta1qt471-py2.6-win32.egg to z:\virtualenv\pyside\lib\site-packages
Adding PySide 1.0.0beta1qt471 to easy-install.pth file
Installing pyside-uic-script.pyc script to Z:\virtualenv\pyside\Scripts
Installing pyside_postinstall.py script to Z:\virtualenv\pyside\Scripts
Installing pyside_postinstall.pyc script to Z:\virtualenv\pyside\Scripts
Installing pyside-uic-script.py script to Z:\virtualenv\pyside\Scripts
Installing pyside-uic.exe script to Z:\virtualenv\pyside\Scripts

Installed z:\virtualenv\pyside\lib\site-packages\pyside-1.0.0beta1qt471-py2.6-win32.egg
Processing dependencies for PySide
Finished processing dependencies for PySide

(pyside) Z:\virtualenv\pyside>python Scripts\pyside_postinstall.py -install
Generating file Z:\virtualenv\pyside\Scripts\qt.conf...
The PySide extensions were successfully installed.
莫相离 2024-08-23 19:10:14

假设您的 virtualenv 名为 myProject 并且您正在使用 virtualenvwrapper。还假设有 Unix 平台。

$ workon myProject
$ pip install --no-install SIP
$ pip install --no-install PyQt
$ cd ~/.virtualenvs/myProject/build/SIP
$ python configure.py
$ make
$ make install
$ cd ~/.virtualenvs/myProject/build/PyQt
$ python configure.py
$ make
$ make install
$ cd && rm -rf ~/.virtualenvs/myProject/build # Optional.

Let's assume your virtualenv is named myProject and you're using virtualenvwrapper. A Unix platform is also assumed.

$ workon myProject
$ pip install --no-install SIP
$ pip install --no-install PyQt
$ cd ~/.virtualenvs/myProject/build/SIP
$ python configure.py
$ make
$ make install
$ cd ~/.virtualenvs/myProject/build/PyQt
$ python configure.py
$ make
$ make install
$ cd && rm -rf ~/.virtualenvs/myProject/build # Optional.
浪漫之都 2024-08-23 19:10:14

最简单的方法是安装这个: vext.pyqt4

这将添加单个系统 PyQt4 打包到你的 virtualenv 中。

Ubuntu 16.04 使用方法:

sudo apt install python3-pyqt4
mkvirtualenv --python=python3.5 venv
pip install --no-use-wheel vext.pyqt4

Easiest way is to install this : vext.pyqt4

This will add the single system PyQt4 package to your virtualenv.

Ubuntu 16.04 usage:

sudo apt install python3-pyqt4
mkvirtualenv --python=python3.5 venv
pip install --no-use-wheel vext.pyqt4
ら栖息 2024-08-23 19:10:14

对于 PySide 1.2.1 和 Ubuntu 12.4

安装编译器、Qt 相关的 python 源

sudo apt-get install cmake qt4-qmake qt-sdk python-dev

使用virtualenvwrapper 创建 virt env

准备编译 Qt(约 30 分钟)

$ mkvirtualenv ve_name
(ve_name)$ pip install PySide

测试

$ python -c "from PyQt4 import QtCore; print QtCore.PYQT_VERSION_STR"
4.9.1

For PySide 1.2.1 and Ubuntu 12.4

Install compilers, Qt related, python sources

sudo apt-get install cmake qt4-qmake qt-sdk python-dev

Create virt env withvirtualenvwrapper

Be ready for compiling Qt (~30 min)

$ mkvirtualenv ve_name
(ve_name)$ pip install PySide

Test

$ python -c "from PyQt4 import QtCore; print QtCore.PYQT_VERSION_STR"
4.9.1
杯别 2024-08-23 19:10:14

如果您在 Mac 上通过 brew 安装了 pyqt(特别是我在 Mavericks 上):

ln -s /usr/local/Cellar/sip/4.15.2/lib/python2.7/site-packages/*.* ~/{VIRTUALENVHOME}/{VIRTUALENVNAME}/lib/python2.7/site-packages
ln -s /usr/local/Cellar/pyqt/4.10.3/lib/python2.7/site-packages/PyQt4/ ~/{VIRTUALENVHOME}/{VIRTUALENVNAME}/lib/python2.7/site-packages/PyQt4
pip install pygments pyzmq 

当然,这些版本文件夹编号可能会随着时间的推移而改变。

If you installed pyqt via brew on a Mac (specifically I'm on Mavericks):

ln -s /usr/local/Cellar/sip/4.15.2/lib/python2.7/site-packages/*.* ~/{VIRTUALENVHOME}/{VIRTUALENVNAME}/lib/python2.7/site-packages
ln -s /usr/local/Cellar/pyqt/4.10.3/lib/python2.7/site-packages/PyQt4/ ~/{VIRTUALENVHOME}/{VIRTUALENVNAME}/lib/python2.7/site-packages/PyQt4
pip install pygments pyzmq 

Of course those version folder numbers may change over time.

对风讲故事 2024-08-23 19:10:14

对我有用的是从 /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/ and sip.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).

滥情稳全场 2024-08-23 19:10:14

扩展 Aaron Digulla 的答案,使用 git 获取正确的文件列表非常方便。我通常会做这样的事情(从 msysGit shell):

# Create temp git repo for the pristine Python installation
$ cd /c/Python27
$ git init -q
$ git add .
$ git commit -qm "Initial commit"

然后运行 ​​PyQt4(或其他)的安装程序。之后,制作安装程序添加的文件的 tarball 并删除临时 git 存储库,如下所示:

# Stage the PyQt4-installed files and feed a list of their names to tar
# (note that there's no need to actually commit them)
$ git add --all
$ git diff --cached --name-only | tar -jcf pyqt4.tar.bz2 --files-from=-
$ rm -rf .git

然后您可以运行 PyQt4 的卸载程序(如果您不想弄乱您的系统 Python),然后简单地解压 pyqt4.tar.bz2 到您的 virtualenv 文件夹中。如果您已经习惯使用 git,这是确保您获得 PyQt4 安装的所有文件的好方法。

注意:使用打包的安装程序安装 PyQt4 也会安装 SIP。如果您确实想要使用此 SIP 在 vi​​rtualenv 中为您自己的 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):

# Create temp git repo for the pristine Python installation
$ cd /c/Python27
$ git init -q
$ git add .
$ git commit -qm "Initial commit"

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:

# Stage the PyQt4-installed files and feed a list of their names to tar
# (note that there's no need to actually commit them)
$ git add --all
$ git diff --cached --name-only | tar -jcf pyqt4.tar.bz2 --files-from=-
$ rm -rf .git

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.)

ら栖息 2024-08-23 19:10:14

符号链接可能有效。

我使用 Linux (Debian/sid)、python 3.4、PySide、virtualenv 和 PyCharm (IDE),但这些相同的指令适用于任何包和开发环境。

/usr/lib/python3/dist-packages/PySide/ $VIRTUAL_ENV/lib/python3.4/site-packages/PySide/ 之间的符号链接对我有用。

cd $VIRTUAL_ENV/lib/python3.4/site-packages/
mkdir PySide
cd PySide`
for x in /usr/lib/python3/dist-packages/PySide/* ; do ln -s $x ; done

有趣的是,如果我仅符号链接 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.

cd $VIRTUAL_ENV/lib/python3.4/site-packages/
mkdir PySide
cd PySide`
for x in /usr/lib/python3/dist-packages/PySide/* ; do ln -s $x ; done

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.

oО清风挽发oО 2024-08-23 19:10:14

试试这个:
pip 安装 python-qt5

Try this one:
pip install python-qt5

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文