[Baypiggies] Python 3 and swig help for m2crypto?
Craig Rodrigues
rodrigc at FreeBSD.org
Wed Nov 18 00:12:47 EST 2015
Hi,
I did the following:
(1) Read "PEP 0328 -- Imports: Multi-Line and Absolute/Relative" (
https://www.python.org/dev/peps/pep-0328/ ) a few times.
(2) Ran "2to3 -f import M2Crypto" to generate a list of places to which
needed fixing of the imports
(3) Applied the patch from (2), and also added "from __future__ import
absolute_import" to all the files
that I touched. This brings in the PEP 328 behavior which is
default in Python 3, back to Python 2.
(4) I tested out this patch:
https://gitlab.com/rodrigc/m2crypto/commit/4e5937ac
Under Python 2.7, the tests passed.
However, I tested the code under Python 3, and got the attached error.
It turns out that the Python C API has changed between Python 2 and Python
3.
So, Python code which uses the C API (such as M2Crypto) needs to be ported.
(!!)
https://docs.python.org/3/howto/cporting.html
--
Craig
On Mon, Nov 16, 2015 at 4:57 PM, Fahrzin Hemmati <fahhem at google.com> wrote:
> I'm not sure, but maybe converting that to a relative import “import
> ._m2crypto” or “from . import _m2crypto” might fix it, but only for python
> 3. Maybe running a specific incantation of 2to3 against the file in the
> build step?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20151117/4476dd15/attachment.html>
-------------- next part --------------
Script started on Tue Nov 17 21:09:51 2015
command: python setup.py test
/usr/home/rodrigc/astrenv/lib/python3.5/site-packages/setuptools/dist.py:285: UserWarning: Normalizing '0.22.6.rc3' to '0.22.6rc3'
normalized_version,
running test
running egg_info
writing M2Crypto.egg-info/PKG-INFO
writing dependency_links to M2Crypto.egg-info/dependency_links.txt
writing top-level names to M2Crypto.egg-info/top_level.txt
reading manifest file 'M2Crypto.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'M2Crypto.egg-info/SOURCES.txt'
running build_ext
copying build/lib.freebsd-10.2-PRERELEASE-amd64-3.5/M2Crypto/__m2crypto.so -> M2Crypto
copying build/lib.freebsd-10.2-PRERELEASE-amd64-3.5/M2Crypto/_m2crypto.py -> M2Crypto
Traceback (most recent call last):
File "setup.py", line 153, in <module>
cmdclass={'build_ext': _M2CryptoBuildExt}
File "/usr/local/lib/python3.5/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/local/lib/python3.5/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python3.5/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/usr/home/rodrigc/astrenv/lib/python3.5/site-packages/setuptools/command/test.py", line 146, in run
self.with_project_on_sys_path(self.run_tests)
File "/usr/home/rodrigc/astrenv/lib/python3.5/site-packages/setuptools/command/test.py", line 127, in with_project_on_sys_path
func()
File "/usr/home/rodrigc/astrenv/lib/python3.5/site-packages/setuptools/command/test.py", line 167, in run_tests
testRunner=self._resolve_as_ep(self.test_runner),
File "/usr/local/lib/python3.5/unittest/main.py", line 93, in __init__
self.parseArgs(argv)
File "/usr/local/lib/python3.5/unittest/main.py", line 140, in parseArgs
self.createTests()
File "/usr/local/lib/python3.5/unittest/main.py", line 147, in createTests
self.module)
File "/usr/local/lib/python3.5/unittest/loader.py", line 219, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/local/lib/python3.5/unittest/loader.py", line 219, in <listcomp>
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/local/lib/python3.5/unittest/loader.py", line 204, in loadTestsFromName
test = obj()
File "/usr/home/rodrigc/2/m2crypto/tests/alltests.py", line 6, in suite
from M2Crypto import m2
File "/usr/home/rodrigc/2/m2crypto/M2Crypto/__init__.py", line 24, in <module>
from . import _m2crypto
File "/usr/home/rodrigc/2/m2crypto/M2Crypto/_m2crypto.py", line 28, in <module>
__m2crypto = swig_import_helper()
File "/usr/home/rodrigc/2/m2crypto/M2Crypto/_m2crypto.py", line 24, in swig_import_helper
_mod = imp.load_module('__m2crypto', fp, pathname, description)
File "/usr/local/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/local/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: /usr/home/rodrigc/2/m2crypto/M2Crypto/__m2crypto.so: Undefined symbol "PyFile_Check"
Script done on Tue Nov 17 21:09:52 2015
More information about the Baypiggies
mailing list