nigma/pywt

Python 3 Support

Closed this issue · 9 comments

I was able to compile the master branch after using 2to3, but it won't import:

In [148]: import pywt
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/home/me/<ipython-input-148-ea1b55fe832f> in <module>()
----> 1 import pywt

/home/me/.local/lib64/python3.2/site-packages/pywt/__init__.py in <module>()
     11 """
     12 
---> 13 import _pywt, multilevel, multidim, wavelet_packets, functions
     14 from _pywt import *
     15 from multilevel import *

ImportError: No module named _pywt

I got this problem once, running ipython directly from the installation folder, which means the uninstalled pywt folder (with no _pywt.so file) overrides the installed one. Can you check pywt.__file__ and see if that folder contains a _pywt.so file?

I often do make that mistake, but in this case I am not running IPython from the build directory.

I am not sure how to check the value of pywt.__file__. Wouldn't I need to be able to import pywt first?

Here are the files that were installed and should be the ones being loaded:

/ $ ls ~/.local/lib64/python3.2/site-packages/pywt/
__init__.py   _pywt.cpython-32m.so  multidim.py    multilevel.pyc  thresholding.py     wavelet_packets.pyc
__init__.pyc  functions.py          multidim.pyc   numerix.py      thresholding.pyc    
__pycache__   functions.pyc         multilevel.py  numerix.pyc     wavelet_packets.py  

Have you tried just renaming _pywt.cpython-32m.so to _pywt.so? (or perhaps a symlink)

I get the same error after renaming to _pywt.so. Could it be my Cython version? I'm using 0.15.1.

Why not try compiling it with python 2, in other words do something like python2.7 setup.py build_ext --inplace and then copy the resulting _pywt.so file into the installed directory with your 2to3 pywt code. I'm not sure about the status of running Cython on Python 3, but I know that libraries that are generated with either version works on both Python 2 and 3.

Hi, I'm afraid binary extensions can only work with python version they were compiled against (there's a lot of macros and version-specific code in the generated source code).

Have you tried using Cython 0.16? I'm going to create a dev branch and see if I can come up with a working solution (I'm still stuck at 2.7 because of web development stuff). Let me know if you have any tips.

Regarding naming of the source folders and importing from the pywt repo directory, I think I'm going to rename it to pywt-src to avoid confusion while running interpreter inside the working directory.

There's now a Python 3 branch at https://github.com/nigma/pywt/tree/py-3 with ported code and demos (doctests are still at v2).

It should work on Python 2.7 and 3.2 from the same codebase (no 2to3 required).

Give it a try with Cython 0.16 and let me know how it works. Thanks.

Somehow that py-3 branch didn't work well for me, but gh-7 should have resolved this. Travis CI builds pass fine with Python 3.3: https://travis-ci.org/rgommers/pywt/builds/12012825

Python 3.x support completed in https://github.com/PyWavelets/pywt, so closing this issue.