PySide's shiboken python module not found - python

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?

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.

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

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.

Related

LHAPDF: undefined symbol when running in Python

I'm trying to use the Python interface for LHAPDF, but I receive the following error message:
Traceback (most recent call last):
File "test.py", line 2, in <module>
import lhapdf
ImportError: /home/n17182559/LHAPDF/lib/python2.7/site-packages/lhapdf.so: undefined symbol: _ZN6LHAPDF6ConfigD1Ev
I'm running on Ubuntu 17.04, using Python 2.7, have Boost installed and have a working C++ compiler (g++). I believe I have successfully installed LHAPDF, as I followed the instructions on their website and got no error message (only warnings that auto_ptr is deprecated, but I don't think I have control over that). I did add the ~/LHAPDF/lib/python2.7/sitepackages/ directory to $PYTHONPATH and ~/LHAPDF/bin/ directory to $PATH. I am using LHAPDF 6.1.6 (latest version as of writing this).
I get this error message from a test.py file that merely contains
#!/usr/bin/python
import lhapdf
If it can help you help me, I have found someone with a similar problem, but the cause seems not to be the same thing (I don't have Anaconda installed). As they solved their problem by removing Anaconda from $PATH, here are my $PATH and $PYTHONPATH as they might be the source of the problem (although I don't see how):
$PATH
/home/n17182559/LHAPDF/bin:/opt/applications/geant4/geant4.10.02-install/bin:/home/n17182559/ROOT/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:
$PYTHONPATH
/home/n17182559/ROOT/lib:/home/n17182559/LHAPDF/lib/python2.7/site-packages:
Hope you guys can help!
I solved it (with external help), if anyone wants the solution. The problem was that the main LHAPDF lib directory was not linked to my LD_LIBRARY_PATH. This command line solved it:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/LHAPDF/lib/libLHAP‌​DF.so
(which I added to my ~/.bashrc file).
I can't speak to your specific problem, but when I get this class of error, it stems from a version mismatch between packages: lhapdf depends on another package to define that arcane "semi-hidden" symbol, but the package on which it depends is of a version different from the one expected; the older/newer version doesn't provide that symbol.
It is a version mismatch (of Python), which is likely caused by upgrading Python after LHAPDF is installed.
Therefore you may have to reinstall LHAPDF, or you could install a second LHAPDF if you use two versions of Python (as of now I am not aware of a solution other than this).
Let us assume you use LHAPDF of version 6.2 or higher, which is much simpler. First you would like to set the path in your shell profile so that it points to the version of Python you want to install LHAPDF for. For bash, you could do
export PATH=path/to/python
then you would like to follow the instruction and do
tar xf LHAPDF-6.X.Y.tar.gz
cd LHAPDF-6.X.Y
./configure --prefix=/path/for/installation
make
make install
After the installation is done, you can add LHAPDF to the path by
export PYTHONPATH=path/to/lhapdf/lib/pythonx.y/site-packages/
export LD_LIBRARY_PATH=path/to/lhapdf/lib
export PATH=path/to/lhapdf/bin/:$PATH
export LHAPDF_DATA_PATH=path/to/lhapdf/share/LHAPDF

ImportError: No module named twisted.persisted.styles

From IDLE, I tried to run a script with a newly installed scrapy 1.0.3.
I'm using a script from a friend whom it worked for (but on Windows, I'm on a Mac).
From the import of scrapy on the first line, I get this error when running the program:
ImportError: No module named twisted.persisted.styles
The whole script, if it's helpful, points to this:
Traceback (most recent call last):
File "/Users/eliasfong/tutorial/tutorial/spiders/medspider.py", line 1, in <module>
import scrapy
File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 27, in <module>
from . import _monkeypatches
File "/Library/Python/2.7/site-packages/scrapy/_monkeypatches.py", line 20, in <module>
import twisted.persisted.styles # NOQA
ImportError: No module named twisted.persisted.styles
Any suggestions on how to tackle this problem?
Just try to force the update of twisted :
pip install twisted --upgrade
That works for me with python3.4 and Scrapy==1.1.0rc1
Either twisted is installed on your mac (I highly doubt it since it's not a standard library) and for whatever reason the IDE (i'm assuming that's what you mean since you typed "idle") or the terminal you are in doesn't have your updated environment variables, meaning it doesn't understand where your default python libraries are (again I highly doubt it), or you simple do not have twisted installed on your mac. If it's not installed you have a couple of options:
The easiest way to install a python package is through pip.
If that not an option you can try homebrew which is another package manager for macs. It offers an easy way to install packages correctly.
If that still is not an option for you or you simply don't want to attempt that you can download twisted directly from here (the .bz2 since you're on a mac), click on it and it should unzip it for you. Then just run setup.py and it should install it in the correct location on your mac.
If that still doesn't work and you have decent knowledge of unix. Use the "locate" command on the terminal and find out where your dist-packages directory is and put the source for twisted in there directly and then attempt to import twisted in your IDE or in the python interpreter to verify that it is installed.
note: If you're still having problems after it is installed trying restarting your IDE or messing with some setting to make sure your IDE has the right environment and python path. Hope that helps!
It could be related to having installed Python without bzip2. I had the same error and this helped me, see the accepted answer here:
Installing Twisted through pip broken on one server
Had this exact thing on FreeBSD. Solution (as root/sudo):
chmod -R go+rX /usr/local/lib/python2.7/site-packages
Some directory permissions weren't set up right on install.

ImportError: No module named Foundation

I am trying to follow the instructions for the accepted answer to "PyObjC development with Xcode 3.2". I will repost them here since I don't have enough rep to comment on the actual question:
Here's what I have done to get PyObjC working in Snow Leopard:
Using the Finder, I went to Go > Connect to Server... and connected to http://svn.red-bean.com/pyobjc/trunk/pyobjc/pyobjc-xcode/ as a guest.
I then made a folder called Xcode on my local system at ~Library/Application Support/Developer/Shared/Xcode/. (You may already have this folder, but I hadn't customized anything for myself yet).
I copied the File Templates folder from the red-bean server into my new Xcode folder.
Copied the Project Templates folder to some other place, for example, the Desktop.
Using the Terminal, navigated to the temporary Project Templates folder on my Desktop and ran this command to "build" the template.:
$ cd ~/Desktop/Project\ Templates/
$ ./project-tool.py -k -v --template ~/Desktop/Project\ Templates/Cocoa-Python\ Application/CocoaApp.xcodeproj/TemplateInfo.plist Cocoa-Python\ Application ~/Library/Application\ Support/Developer/Shared/Xcode/Project\ Templates/Cocoa-Python\ Application
When I try to run the line that starts with ./project-tool.py, I get the following error in Terminal:
Traceback (most recent call last):
File "./project-tool.py", line 22, in <module>
from Foundation import NSDictionary
ImportError: No module named Foundation
I am running Snow Leopard and have installed Xcode 3.2.1 and have read that this module should already be installed and working. I've read that you can test if the PyObjC modules are working by running >>> import objc in the Python command-line. When I run this, I get:
>>> import objc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named objc
Could anyone help me dispel this error? It seems like I should be able to do all of this automatically with my Snow Leopard installation, but I can't.
I had the same problem. Mine was caused I think by using homebrew to install my own Python to tinker with.
Because I was worried about mixing python versions, rather than creating the link as described above, I installed a new pyobjc using:
$ pip install pyobjc
For interest, from (http://pythonhosted.org/pyobjc/)
The PyObjC project aims to provide a bridge between the Python and Objective-C programming languages.
Okay, it turned out that, amending mjv's answer, I was able to get it working by typing
export PYTHONPATH="/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/PyObjC/"
before executing the ./project-tool.py line. I still find it ridiculous that I had to do this and if anyone can see why, I would be delighted to know.
Doing this also got the
>>> import objc
line working.
It's because PyObjC is there :
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC
Edit :
I found how to make "import objc" work, just :
export PYTHONPATH="/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/"
It will add all the directories to the python path (sys.path)
for python 2.7
export PYTHONPATH="/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/"
One of two things:
Either the Fundation module doesn't exists
Or Python interpretor doesn't know when to find this file
Python looks for modules in the PythonPath
See this SO question for more details on how Python Path is created etc.
Run python -v to trace import statements, this work for interactive mode too.
I could access a Python installation with Foundation on my OSX by running /usr/bin/python file-to-run.py
remove your python or remove site-packages/Foundation | site-packages/foundation
pip3 install pyobjc
the name Foundation is in conflict with https://pypi.org/project/foundation/
I found the foundation folder in /usr/local/lib/python3.9/site-packages/ next to the AppKit folder. After renaming it to Foundation (with uppercase F), the import worked. The Filesystem is not case-sensitive but it seems some part of the import implementation is.
Saw it mentioned in another comment and I too ran into this problem due to installing Python via homebrew. My pyobjc installation wound up going to the Python homebrew installation, yet my pythonpath was linked to the Python that comes bundled with macOS, so there was this big disconnect and I had no luck getting pythonpath re-routed in .zshrc or .zprofile.
In the end, these steps resolved the issue:
brew uninstall python
pip3 install -U pyobjc

How to get _sqlite3.so file?

I have installed Python 2.6.2.. I did it "locally" since I do not have root permissions. With this version of Python I wanted to use module called "sqlite3" (it is called "pysqlite" in earlier versions). In theory I had to be able to use this module without any problems since it is supposed to be included by default in the considered version of Python. However, I have some troubles. When I type:
from sqlite3 import *
I get:
Traceback (most recent call last):
File "", line 1, in File "/home/verrtex/opt/lib/python2.6/sqlite3/init.py", line 24, in
from dbapi2 import *
File "/home/verrtex/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in
from _sqlite3 import *
ImportError: No module named _sqlite3
As I have already told to, the possible reason of this problem is that the module in tries to import _sqlite3 and fails, so it's not finding _sqlite3.so. This explanations is supported by the fact that I do not have _sqlite3.so file in my "/home/verrtex/opt/lib/python2.6/lib-dynload" directory. So, this is the problem I have to solve (I have to get this file to this directory).
I found out that to solve this problem I have to "install sqlite3 and recompile Python". I also found out that the problem can be solved by "building from source and moving the library to /usr/lib/python2.5/lib-dynload/".
However, it is not clear to me what exactly should I do. Should I install python module called "sqlite3" or I should install sqlite-database? By the way, I have already sqlite-database installed globally by the administrator. Can I use it or I still have to install my own database? By the way, I do not have root permissions. Can it be a problem? Or I need to install a python module? Is absence of root permissions a problem, in this case?
I also has been told to, to take source files from SQLite Download Page, extract archive, move to expanded directory and execute:
./configure
make
make install
Then I have to copy newly compiled files to my Python directory. Should I copy all newly compiled files? And to which exactly directory should I copy (my Python directory have some subdirectories)?
Would very appreciate any help, because I stack with this problem for a wile.
P.S. My OS is CentOS release 5.3 (Final).
Your sys.path is likely not pointing to your locally installed copy, or you're not running the Python 2.6.2 you think you are.
If none of that is the case, you need the SQLite development headers (sqlite-dev or whatever), and then recompile Python. You need to pay attention at the end of the compile, because it complains about what it didn't build due to missing dependencies.
EDIT: Reread question.
EDIT 2: Also, please don't do this:
from module import *
Do this:
from module import what_i_need
import module2
Although you might have found your solution, I just wrote mine down for someone who are stuck in the same problem.
My OS is CentOS 6.3(Final) with python2.6.
I install python2.7.3 in my system, but the problem's still there. (_sqlite3.so should be in /path/to/python2.7.3/lib/python2.7/lib-dynload after python2.7.3 has been installed. Because before python2.7 was installed, sqlite-autoconf-3071502.tar.gz was installed.)
I then copy the /path/to/python2.6/lib/python2.6/lib-dynload/_sqlite3.so to the python2.7's path. And type in the python-shell:
>>> import sqlite3
or
>>> import _sqlite3
No error reports.
Unfortunately, the damn error appeared as before when I run my python script.
I install sqlite-devel(sudo yum install sqlite-devel or download here), and then reinstall python2.7.3 again. Run my python script again. Thank goodness! The damn error finally solved.

How to find out if I have installed a Python module in Linux?

I tried to install a Python module by typing: sudo python setup.py install
After I typed this command I got a lot of output to the screen.
The lest few lines are bellow:
writing manifest file 'scikits.audiolab.egg-info/SOURCES.txt'
removing '/usr/lib/python2.5/site-packages/scikits.audiolab-0.10.2-py2.5.egg-info' (and everything under it)
Copying scikits.audiolab.egg-info to /usr/lib/python2.5/site-packages/scikits.audiolab-0.10.2-py2.5.egg-info
Installing /usr/lib/python2.5/site-packages/scikits.audiolab-0.10.2-py2.5-nspkg.pth
running install_scripts
So, there were nothing suspicious. But when I tried to use the module from the Python:
import pyaudiolab
I see that Python does not find the module:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import pyaudiolab ImportError: No module named pyaudiolab
How can I found out what went wrong? As a result of the installation I get a new directory:
/usr/lib/python2.5/site-packages (so something happened) but I still cannot use the module. Can anybody help me with that?
Have you tried import scikits.audiolab or import audiolab?
From the OP's comment to an answer, it's clear that scikits.audiolab is indeed where this module's been installed, but it also needs you to install numpy. Assuming the module's configuration files are correct, by using easy_install instead of the usual python setup.py run, you might have automatically gotten and installed such extra dependencies -- that's one of the main points of easy_install after all. But you can also do it "manually" (for better control of where you get dependencies from and exactly how you install them), of course -- however, in that case, you do need to check and manually install the dependencies, too.
Your library depends upon numoy. Try installing numpy:
sudo apt-get install python-numpy
You need a more recent version of numpy (>= 1.2.0), as indicated on the audiolab installation informations.
check if you have the module somewhere inside:
/usr/lib/python2.5/site-packages/
(search for a file named |modulename|.py so in your example - try: pyaudiolab.py or audiolab.py)
if it exists - check if the directory in which it exists is found in the sys.path variable:
import sys
sys.path

Categories