VirtualEnv未正确设置路径,无法使用已安装的模块

时间:2017-04-11 18:58:47

标签: python pyqt4 virtualenv python-sip

简短版本:我如何让PyQt4的configure.py使用Virtual Env中安装的SIP版本?

长版: 我知道这个问题的变化在这里被问过一百万次,但我似乎无法找到答案。我正在尝试在虚拟环境(VE)中安装SIP和PyQt4。我无法将其安装到主系统,因为它是一台工作计算机。我们有一个较旧版本的PyQt,因此我无法从网站包中复制。

我在我的VE中安装了SIP(configure.py --incdir,make,make install)但是当我在PyQt4上运行configure时出现错误:错误:此版本的PyQt需要SIP v4.19.0或更高版本。我安装了4.19.2版。当运行sipconfig时,它告诉我它仍在使用系统版本,即使激活了VE。如何告诉configure.py PyQt使用VE中安装的软件包?

谢谢大家!

编辑:看起来,看起来我的VE并没有从正确的地方拉出python库,即使VE被激活了。我添加了一行来激活将site-packages和bin dirs的路径和site-packages附加到pythonpath而没有成功。它仍然没有找到正确的库。

3 个答案:

答案 0 :(得分:1)

您无需从源代码构建SIP。这里有轮子文件https://pypi.python.org/pypi/SIP

在我的情况下,在macos上,我不得不下载方向盘并将其重命名以欺骗安装它:

$ curl -L -O 'https://pypi.python.org/packages/f9/8c/23d88c8e4d457031111b70ec25bf97844776ec16cfd4688f318dcaeba5d6/sip-4.19.2-cp35-cp35m-macosx_10_6_intel.whl#md5=eb42e9975cae2b936ecc980b9a3266ed'
$ mv sip-4.19.2-cp35-cp35m-*.whl sip-4.19.2-cp35-none-macosx_10_11_x86_64.whl
$ pip install sip-4.19.2-cp35-none-macosx_10_11_x86_64.whl

皮普相当愚蠢。文件名必须与pip知道的平台相匹配。

然后,我可以使用python configure-ng.py进行安装(在使用brew upgrade qt将我的mac上的qt从5.5升级到5.8后,由于错误https://forum.qt.io/topic/71119/project-error-xcode-not-set-up-properly/7

然后我得到了一个很好的错误:

$ python configure-ng.py --verbose
Querying qmake about your Qt installation...
Determining the details of your Qt installation...
/usr/local/Cellar/qt5/5.8.0_2/bin/qmake -o qtdetail.mk qtdetail.pro
Info: creating stash file /Users/jrwren/Downloads/PyQt4_gpl_mac-4.12/.qmake.stash
make -f qtdetail.mk
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.9  -O2 -std=gnu++11 -Wall -W -fPIC -DQT_NO_DEBUG -DQT_CORE_LIB -I. -I/usr/local/Cellar/qt/5.8.0_2/lib/QtCore.framework/Headers -I. -I/usr/local/Cellar/qt/5.8.0_2/mkspecs/macx-clang -F/usr/local/Cellar/qt/5.8.0_2/lib -o qtdetail.o qtdetail.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -stdlib=libc++ -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.9  -o qtdetail.app/Contents/MacOS/qtdetail qtdetail.o   -F/usr/local/Cellar/qt/5.8.0_2/lib -framework QtCore -framework DiskArbitration -framework IOKit
qtdetail.app/Contents/MacOS/qtdetail
This is the GPL version of PyQt 4.12 (licensed under the GNU General Public
License) for Python 3.5.1 on darwin.
Error: This version of PyQt4 and the commercial version of Qt have incompatible
licenses.

但它不是SIP错误。

答案 1 :(得分:1)

在您的虚拟环境中安装pip。并使用ConfigurationSection检查pip是否正在使用正确的目录。如果未使用正确的目录,请尝试以下操作:

which pip

如果出现名为“拒绝权限”的错误,请使用

pip install --target=<location of site packages of your pip in your virtual env> sip==4.19

然后做:

sudo chown -R your_username:your_username path/to/virtuaelenv/

如果上述方法均无效,请按照以下说明操作:

github project

答案 2 :(得分:1)

尝试使用anaconda anaconda是一个python发行版,包括一个替代的包管理器(除了pip)和一个替代的虚拟env机制

conda包与conda venv机制配合良好,因此您不应该遇到这些问题,也不需要修改第三方脚本或手动创建链接

https://www.continuum.io/downloads

安装

创建虚拟环境运行

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button">Hello</button>
    <button type="button">Bye</button>

激活venv

conda create -n <name>

(使用shell \ bash时)

安装pyqt run:

source activate <name>
相关问题