ricedsp/rwt

Anaconda Support / Fatal Python error: PyThreadState_Get: no current thread

WillemMarais opened this issue · 3 comments

I'm using Anaconda as my python distribution (on a Mac). When I try to compile rwt on my system against Anaconda, I get an error as shown in the title of this issue. There are possibly three reasons for this:

  1. The cmake cache variables PYTHON_LIBRARY and PYTHON_INCLUDE_DIR are not properly set. I think these should be explicitly set using the cmake -D flag; there is maybe another way of doing this?
  2. The filesystem path to the dynamic library _rwt.so is not properly set, even if PYTHON_LIBRARY and PYTHON_INCLUDE_DIR are properly set. This is can be fixed using the install_name_tool command with the parameter -change.
  3. I'm using a more recent version of numpy (1.9.2). It seems that the numpy swig configuration file that is in rwt is for version 1.7 (I could be incorrect).

Below are information that shows the problem and the fix. If a user, like me, wants to install rwt alongside Anaconda, could you add instructions in the documentation to show how it can be done?

SHOWING SYSTEM INFORMATION

uname -a 

Darwin hostname 14.4.0 Darwin Kernel Version 14.4.0: Datetime 2015; root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64

printenv

TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/jp/bbbjnpys6n1dsbpw8wtm9bxh0000gp/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.b0806cvhV9/Render
TERM_PROGRAM_VERSION=343.7
OLDPWD=$HOME/Temp
TERM_SESSION_ID=BC756C22-A12E-4817-847B-913DFB4F5FAE
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.3QWtJEqlQO/Listeners
__CF_USER_TEXT_ENCODING=0x1F6:0x0:0x0
PATH=$HOME/Apps/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/texbin
PWD=$HOME/Temp/rwt/python
EDITOR=mate
LANG=en_US.UTF-8
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
SHLVL=1
DISPLAY=/private/tmp/com.apple.launchd.G3vnOgR0aM/org.macosforge.xquartz:0
_=/usr/bin/printenv

conda --version

conda 3.15.1

python -c 'import numpy;print (numpy.version.full_version)'

1.9.2

which python

$HOME/Apps/anaconda/bin/python

SHOWING THE COMPILER WARNING AND ERROR

svn co https://github.com/ricedsp/rwt/trunk rwt
cd rwt/python
cmake .
make

$HOME/Apps/anaconda/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning:
"Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]

warning "Using deprecated NumPy API, disable it by " \

^
1 warning generated.
[ 37%] Building C object CMakeFiles/_rwt.dir/Users/willemm/Temp/rwt/lib/src/dwt.c.o
[ 50%] Building C object CMakeFiles/_rwt.dir/Users/willemm/Temp/rwt/lib/src/idwt.c.o
[ 62%] Building C object CMakeFiles/_rwt.dir/Users/willemm/Temp/rwt/lib/src/rdwt.c.o
[ 75%] Building C object CMakeFiles/_rwt.dir/Users/willemm/Temp/rwt/lib/src/irdwt.c.o
[ 87%] Building C object CMakeFiles/_rwt.dir/Users/willemm/Temp/rwt/lib/src/platform.c.o
[100%] Building C object CMakeFiles/_rwt.dir/Users/willemm/Temp/rwt/lib/src/init.c.o
Linking CXX shared module _rwt.so

make install
python -c 'import rwt'

Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6

SHOWING THE FIX TO BOTH THE COMPILER WARNING AND ERROR

make clean

Get most recent copy of numpy SWIG configuration file. Download numpy-1.9.2 source file to
home directory

cp $HOME/numpy-1.9.2/tools/swig/numpy.i .
cmake -D PYTHON_LIBRARY=$HOME/Apps/anaconda/lib/libpython2.7.dylib -D PYTHON_INCLUDE_DIR=$HOME/Apps/anaconda/include/python2.7 .
make
otool -L _rwt.so 

_rwt.so:
libpython2.7.dylib (compatibility version 2.7.0, current version 2.7.0)
/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 1213.0.0)

install_name_tool -change libpython2.7.dylib $HOME/Apps/anaconda/lib/libpython2.7.dylib _rwt.so
otool -L _rwt.so 

_rwt.so:
$HOME/Apps/anaconda/lib/libpython2.7.dylib (compatibility version 2.7.0, current version 2.7.0)
/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 1213.0.0)

make install
python -c 'import rwt'

Success

When I follow the install documentation under Python 3.4 on OSX, my install fails, even when I add an additional command make. Could the documentation be clarified for the Python installation like @WillemMarais requested?

I get output from cmake . that indicates that it found my system PythonLibs and SWIG while relying on Anaconda python/numpy. However, I cannot parse the above comment and don't know what each step does. @WillemMarais could you please clean up your comment and format it nicely?

> cd rwt/python
> cmake .
...
-- Found SWIG: /usr/local/bin/swig (found version "3.0.2")
-- Found PythonLibs: /usr/lib/libpython2.7.dylib (found version "2.7.3")
python: /Users/scott/anaconda/bin/python
numpy : /Users/scott/anaconda/lib/python3.4/site-packages/numpy/core/include
...
> make
...
Linking CXX shared module _rwt.so
[100%] Built target _rwt
> sudo make install
> python
>>> import rwt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/scott/Downloads/rwt-master/python/rwt.py", line 35, in <module>
    _rwt = swig_import_helper()
  File "/Users/scott/Downloads/rwt-master/python/rwt.py", line 31, in swig_import_helper
    _mod = imp.load_module('_rwt', fp, pathname, description)
  File "/Users/scott/anaconda/lib/python3.4/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
ImportError: dynamic module does not define init function (PyInit__rwt)

When I run this under Python 2.7 using a conda virtualenv, I get the same error as above PyThreadState_Get: no current thread

@stsievert were you able to fix the ImportError ?
I am using a similar setup: Anaconda with Python 3.5 and I get the Import Error dynamic module does not define init function (PyInit__rwt)

No, I have moved to PyWavelets. My biggest barrier in using this was that PyWavelets doesn't return a ndarray of the entire wavelet transform but instead returns a tuple of tuples of lists. PyWavelets PR #168 rectifies this.