如何在Raspberry Pi3的Python3虚拟环境中安装PySide2

时间:2019-02-13 13:27:31

标签: virtualenv python-3.5 raspberry-pi3 pyside2

我很难在Raspberry Pi3的Python3虚拟环境中安装PySide2。我使用的是 Python-3.5.3 pip 的更新版本。

(cv3) pi@raspberrypi:~ $ which cmake
/usr/bin/cmake
(cv3) pi@raspberrypi:~ $ which qmake
/usr/bin/qmake
(cv3) pi@raspberrypi:~ $ which python
/home/pi/.virtualenvs/cv3/bin/python
(cv3) pi@raspberrypi:~ $ python --version
Python 3.5.3
(cv3) pi@raspberrypi:~ $ pip --version
pip 19.0.1 from /home/pi/.virtualenvs/cv3/lib/python3.5/site-packages/pip (python 3.5)
(cv3) pi@raspberrypi:~ $ pip3 --version
pip 19.0.1 from /home/pi/.virtualenvs/cv3/lib/python3.5/site-packages/pip (python 3.5)

首先,我尝试使用pip install PySide2安装,但出现错误

(cv3) pi@raspberrypi:~ $ pip install PySide2
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting PySide2
Could not find a version that satisfies the requirement PySide2 (from versions: )
No matching distribution found for PySide2

遵循https://wiki.qt.io/Qt_for_Python/GettingStarted上有关如何通过Qt for Python官方发行版进行安装的说明,也会出现错误。

(cv3) pi@raspberrypi:~ $ pip install --index-url=https://download.qt.io/official_releases/QtForPython/ pyside2 --trusted-host download.qt.io
Looking in indexes: https://download.qt.io/official_releases/QtForPython/, https://www.piwheels.org/simple
Collecting pyside2
Could not find a version that satisfies the requirement pyside2 (from versions: )
No matching distribution found for pyside2

然后,我按照官方软件包站点https://pypi.org/project/PySide2/上的说明进行操作。我安装了包括 libclang 在内的依赖项,并按照建议从源代码进行构建,没有任何错误。

git clone https://code.qt.io/pyside/pyside-setup
cd pyside-setup
git branch --track 5.12 origin/5.12
git checkout 5.12
python setup.py install --qmake=</usr/bin/qmake/> --parallel=8 --build-tests

尽管完成了所有这些工作,但没有PySide2模块的迹象

(cv3) pi@raspberrypi:~/pyside-setup $ python
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PySide2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'PySide2'
>>>

接下来,我按照https://wiki.qt.io/Qt_for_Python/GettingStarted/X11上的说明进行操作。我克隆了官方存储库,检查版本是否正确,然后使用 qmake 路径/opt/Qt5.12/bin/qmake构建:

(cv3) pi@raspberrypi:~/pyside-setup $ python setup.py build --qmake=/opt/Qt5.12/bin/qmake --parallel=4 --build-tests --ignore-git

,该版本产生了两个错误:     CMakeLists.txt:95的CMake错误(消息):     无法通过检查LLVM_INSTALL_DIR,CLANG_INSTALL_DIR或运行llvm-config来检测CLANG的位置。

-- Configuring incomplete, errors occurred!
See also "/home/pi/pyside-setup/cv33_build/py3.5-qt5.12.0-32bit-release/shiboken2/CMakeFiles/CMakeOutput.log".
error: Error configuring shiboken2

我猜想也许更新 CLANG CMAKE 会有所改变。因此,我将其更新为最新版本,并且过程进行顺利,没有错误。然后我

在构建PySide2时,该进程以47%退出,并出现以下错误:

[ 47%] Linking CXX executable shiboken2
/home/pi/libclang/lib/libclang.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
generator/CMakeFiles/shiboken2.dir/build.make:181: set di istruzioni per l'obiettivo "generator/shiboken2" non riuscito
make[2]: *** [generator/shiboken2] Errore 1
CMakeFiles/Makefile2:2877: set di istruzioni per l'obiettivo "generator/CMakeFiles/shiboken2.dir/all" non riuscito
make[1]: *** [generator/CMakeFiles/shiboken2.dir/all] Errore 2
Makefile:140: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2
error: Error compiling shiboken2
Traceback (most recent call last):
File "setup.py", line 296, in <module>
setup_runner.run_setup()
File "/home/pi/pyside-setup/build_scripts/setup_runner.py", line 157, in run_setup
raise RuntimeError(msg)
RuntimeError: 
setup.py invocation failed with exit code: 1.


setup.py invocation was: /home/pi/.virtualenvs/cv3/bin/python setup.py build --qmake=/opt/Qt5.12/bin/qmake --parallel=4 --build-tests --ignore-git --internal-build-type=shiboken2

问题出在哪里?

1 个答案:

答案 0 :(得分:0)

由于安装的CLANG的版本已过时,我首先按照codepool.biz上的说明尝试对其进行更新。没有问题。

然后我再次使用{p>将指向LLVMCLANG的库指向PySide2安装路径。

export CLANG_INSTALL_DIR=/usr/local/clang_7.0.
export LLVM_INSTALL_DIR=/usr/local/clang_7.0.0

构建过程成功通过了47%的树桩并完成了shiboken2的扩建,但在PySide2步骤中停留了2%。错误:

[  2%] Built target pyside2
Makefile:140: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2
error: Error compiling pyside2
Traceback (most recent call last):
   File "setup.py", line 296, in <module>
      setup_runner.run_setup()
   File "/home/pi/pyside-setup/build_scripts/setup_runner.py", line 157, in run_setup
      raise RuntimeError(msg)
RuntimeError: 
setup.py invocation failed with exit code: 1.

setup.py invocation was: /home/pi/.virtualenvs/cv3/bin/python setup.py build --qmake=/opt/Qt5.12/bin/qmake --parallel=4 --build-tests --ignore-git --internal-build-type=pyside2

这是怎么回事?