Program Tip

Virtualenv 샌드 박스에 PyQt4 / PySide 패키지를 추가 할 수 있습니까?

programtip 2020. 12. 6. 22:01
반응형

Virtualenv 샌드 박스에 PyQt4 / PySide 패키지를 추가 할 수 있습니까?


, 및 기타 웹 지향 패키지를 사용하여 개발 환경에서 이익을 얻고 Virtualenv사용 하고 있습니다. web.py로 개발 된 일부 API를 재사용하기 위해 Qt를 사용하여 간단한 파이썬 클라이언트를 개발할 것입니다.web.pysimplejson

여기에 Virtualenv와 함께 PyQt4를 성공적으로 설치 한 사람이 있습니까?
가능합니까?

모든 바이너리를 다운로드하고 PyQt4python2.6 디렉토리에 전역 적으로 설치했습니다. 옵션을
사용하지 않으면 --no-site--packagesVirtualenv는 PyQt4새 샌드 박스에 올바르게 포함 되지만 필요하지 않은 모든 글로벌 패키지를 포함합니다.

--no-site--packages옵션을 사용하여 새 샌드 박스를 준비한 다음 , 또는 다른 마술 을 추가 PyQt4하거나 PySide사용 하는 깨끗한 방법이 있습니까?pipeasy_install


빈 virtualenv를 만든 다음 .../site-packages/PyQt4디렉토리 의 내용을 여기에 복사하는 것으로 충분 합니다.

나는 PyQt4를 전역 적으로 한 번 설치하고, 디렉토리의 사본을 만들고, 제거한 다음이 트릭을 사용하여 VE를 만드는 것이 좋습니다.


나도 같은 문제를 안고있어. 나는 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

요점 링크


Linux debian, python 2.7 :

  • python-qt4 globaly를 설치합니다. 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/

Python 3 virtualenv (OSX에서)에서 PyQt4를 사용하려면 먼저 PyQt4 및 SIP를 설치합니다 (homebrew를 사용합니다)

$ 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

irc.freenode.net #pyside 채널의 virtualenv 내에서 PySide를 설치할 수 있는지 물었고 hugopl으로부터 긍정적 인 답변을 받았습니다 . 그래서 Microsoft Windows 용 PySide Binaries의 지침을 따랐고 작동했습니다. 출력은 다음과 같습니다.

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.

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.

가장 쉬운 방법은 이것을 설치하는 것입니다 : vext.pyqt4

그러면 PyQt4virtualenv에 단일 시스템 패키지 가 추가됩니다 .

Ubuntu 16.04 사용법 :

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

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

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.


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


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


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.


Try this one: pip install python-qt5

참고URL : https://stackoverflow.com/questions/1961997/is-it-possible-to-add-pyqt4-pyside-packages-on-a-virtualenv-sandbox

반응형