PySide's shiboken python module not found

2019-06-01 02:06发布

问题:

PySide is installed successfully, and it works perfectly, but I can't find a way to import the shiboken module. Now I found the discussion about the feature request to expose shiboken functions through a python module (http://bugs.pyside.org/show_bug.cgi?id=902), but the issue is resolved. It was implemented in january 2012, if I understood correctly. Even though after the installation of PySide 1.1.1 when I try:

>>> import shiboken
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named shiboken

I get an ImportError exception. How can I install the shiboken python module?

回答1:

Looks like someone forgot to update cmake: bugs-PYSIDE-55.

However, I've just compiled shiboken-1.1.2, and the issue seems to be fixed.



回答2:

I beleive under ideal circumstances ekhumoro's answer is totally correct, unfortunately I was not that lucky, and the binary packages still didn't allow the usage of the shiboken python module. I had to compile it manually, but that part became tricky too as it didn't work by the default instructions found on their homepage, probably because I'm using ubuntu 12.04, or I'm not sure why else. As the target was the usage from withing a virtualenv I followed these instructions:

export PYSIDESANDBOXPATH=/path/to/my/virtualenv
export PATH=$PYSIDESANDBOXPATH/bin:$PATH
export PYTHONPATH=$PYSIDESANDBOXPATH/lib/python2.6/site-packages:$PYTHONPATH
export LD_LIBRARY_PATH=$PYSIDESANDBOXPATH/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$PYSIDESANDBOXPATH/lib/pkgconfig:$PKG_CONFIG_PATH

mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$PYSIDESANDBOXPATH -DCMAKE_BUILD_TYPE=Debug -DENABLE_ICECC=0'
make
make install
sudo ldconfig

The first problem here was that after it was compiled, and the installation began, and it wanted to install the shiboken python module, this happend:

-- Installing: .../lib/python2.7/site-packages/shiboken.so
-- Removed runtime path from .../lib/python2.7/site-packages/shiboken.so

Then I found somewhere that I should add this parameter to cmake:

-DCMAKE_SKIP_RPATH:BOOL=YES

Now the installation was successful, but when I tried to import shiboken in python, this happened:

import shiboken
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libshiboken.so: cannot open shared object file: No such file or directory

Google revealed that the issue is caused because $LD_LIBRARY_PATH does not contain the path where those libs are located. First of all ubuntu 12 (and I think 10 and 11 also) does not use the $LD_LIBRARY_PATH environment variable anymore, so it was not even set. So even the path was incorrect because I tried to join that unset variable with a path:

export LD_LIBRARY_PATH=$PYSIDESANDBOXPATH/lib:$LD_LIBRARY_PATH

So it treated it as two regular strings and just joined them together. The snippet below shows how to join them safely to avoid causing such troubles. But that didn't solve the problem either. as running ldconfig still didn't update anything, so the importing in python failed again. The final solution found with google too :) was creating a new file in /etc/ld.so.conf.d/ and put there the contents of $LD_LIBRARY_PATH, and run ldconfig after that. So here is the final install script which worked as expected:

#!/usr/bin/env bash
export PYSIDESANDBOXPATH=/path/to/my/virtualenv
export PATH="$PYSIDESANDBOXPATH/bin${PATH:+:$PATH}"
export PYTHONPATH="$PYSIDESANDBOXPATH/lib/python2.7/site-packages${PYTHONPATH:+:$PYTHONPATH}"
export LD_LIBRARY_PATH="$PYSIDESANDBOXPATH/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export PKG_CONFIG_PATH="$PYSIDESANDBOXPATH/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"

mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$PYSIDESANDBOXPATH -DCMAKE_SKIP_RPATH:BOOL=YES -DCMAKE_BUILD_TYPE=Debug -DENABLE_ICECC=0
make
make install
sudo sh -c "echo $LD_LIBRARY_PATH > /etc/ld.so.conf.d/shiboken.conf"
sudo ldconfig

That's all, it cost me several hours to figure out, hope this will save someone else :)



回答3:

Here's how I compile shiboken.pyd on Windows from source code, tested with PySide-1.1.2 + Qt4.8.4 + msvc2010.

First, manually download shiboken-1.1.2.tar.bz2, extract it. Then compile it this way (you might need to set up virtualenv):

python setup.py build --openssl=C:\dev\OpenSSL\1.0.0j\bin --qmake=C:\Qt\4.8.4\bin\qmake.exe

After it finished, I got shiboken.pyd at:

PySide-1.1.2\pyside_install\py2.7-qt4.8.4-32bit-release\lib\site-packages\shiboken.pyd

P.S.

However, shiboken.pyd was missing in "PySide-1.1.2\build\lib", where files would be installed to site-packages. This explains why I coundn't get shiboken.pyd by compiling PySide from PIP using:

pip install PySide --install-option="--openssl=C:\dev\OpenSSL\1.0.0j\bin" --install-option="--qmake=C:\Qt\4.8.4\bin\qmake.exe"

btw, on Mac OS X, if you install PySide using macports, "import shiboken" will also fail, because it is installed into the wrong location ("/opt/local/lib/python2.7/site-packages" instead of "/opt/local/Library/Frameworks/Python.framework/Version/2.7/lib/python2.7/site-packages"). Add "/opt/local/lib/python2.7/site-packages" to PYTHONPATH will solve the issue.

There are definitely bugs in the pyside-setup scripts. Hope Digia could send somebody to fix PySide before the project goes dead.