Py学习  »  Python

(mac环境)非brew安装的python 安装 pyside

Py站长 • 9 年前 • 5654 次点击  

(mac环境)非brew安装的python 安装 pyside

我的python不是使用brew安装的,按照 http://pyside.readthedocs.org/en/latest/building/macosx.html 这里安装 了 pyside后,

想要 玩耍

http://qt-project.org/wiki/Hello_World_in_PySide

from PySide.QtGui import QApplication
from PySide.QtGui import QMessageBox

一直报错:

>>> from PySide.QtGui import QApplication
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/knightliao/baiduyun/dev/pythonvir/online/lib/python2.7/site-packages/PySide/QtGui.so, 2): Symbol not found: __Z13init_QPrinterP7_object
  Referenced from: /Users/knightliao/baiduyun/dev/pythonvir/online/lib/python2.7/site-packages/PySide/QtGui.so
  Expected in: dynamic lookup

无论怎么搞也搞不定。

我使用 otool 看一下 动态 库依赖:

(online)➜  PySide  otool -L QtGui.so
QtGui.so:
    @rpath/libpyside-python2.7.1.2.dylib (compatibility version 1.2.0, current version 1.2.2)
    @rpath/libshiboken-python2.7.1.2.dylib (compatibility version 1.2.0, current version 1.2.2)
    /usr/local/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.8.0, current version 4.8.6)
    /usr/local/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.6)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 60.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 2577.0.0)

貌似也看不出哪里出错了。。。

按照 http://pyside.readthedocs.org/en/latest/building/macosx.html 这个教程:

我怀疑 问题出在:

  1. 使用brew安装了qt
  2. 使用未用brew安装的python
  3. 未使用brew安装的pyside

因此,我打算

  1. 使用brew安装qt
  2. 使用brew安装pyside
  3. 将编译出来的pyside copy 到 你自己的python的site-package里

具体就是:

  1. brew rm qt
  2. brew rm cmake
  3. brew rm shiboken
  4. brew cleanup --force
  5. brew prune
  6. brew install pyside

安装完之后,brew 提示

If you need Python to find the installed site-packages:
  mkdir -p ~/Library/Python/2.7/lib/python/site-packages
  echo '/usr/local/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
==> Summary

我看了一下这个目录

➜  ~  ls /usr/local/lib/python2.7/site-packages
PySide      shiboken.so

并且再定位一下动态库:

➜  PySide git:(master) otool -L QtGui.so
QtGui.so:
    /usr/local/Cellar/pyside/1.2.2/lib/libpyside-python2.7.1.2.dylib (compatibility version 1.2.0, current version 1.2.2)
    /usr/local/lib/libshiboken-python2.7.1.2.dylib (compatibility version 1.2.0, current version 1.2.2)
    /usr/local/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.8.0, current version 4.8.6)
    /usr/local/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.6)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

那么,这里就可以确定 /usr/local/lib/python2.7/site-packages 这个就是 brew 安装出来的 pyside

将/usr/local/lib/python2.7/site-packages 这个目录的所有内容复制到你的 python的site-package目录,然后 pyside就不会报错了。

具体原因,我觉得应该是必须使用 brew 来安装pyside,否则貌似 qt会找不到动态库。

深层原因我也不知道了。

PS:

经验证,此方法 只能对于和(>=)系统的python版本的python环境兼容。例如,你的virtual python的版本是小于你的系统python版本,那么它不能work.

另外,不要在你的.bash_profile里 的 LD_LIBRARY_PATH 这个变量设置与python版本有关的变量。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/690
 
5654 次点击