Discussion:
[Py2exe-users] ctypes.pythonapi fails
Okko Willeboordse
2016-11-08 13:38:09 UTC
Permalink
Hello,

I run in to problems converting a PyQt4/matplotlib application in to a
single executable.

matplotlib does the following;

_decref = ctypes.pythonapi.Py_DecRef

ctypes help; "pythonapi is a predefined symbol giving access to the Python
C api:"

Apparently py2exe loads ctypes such that ctypes.pythonapi is not valid,
since my application fails with;

File "zipextimporter.pyc", line 82, in load_module
File "matplotlib\backends\backend_qt5agg.pyc", line 31, in <module>
File "ctypes\__init__.pyc", line 375, in __getattr__
File "ctypes\__init__.pyc", line 380, in __getitem__
AttributeError: function 'Py_DecRef' not found

I can override ctypes.pythonapi before importing matplotlib as follows;

ctypes.pythonapi = ctypes.PyDLL('python%d%d.dll' % sys.version_info[:2])

With above override things work, however plain wrong since the application
now has 2 interpreters (read python dll's);
one loaded by py2exe and one by the override.

If I could get a handle to the interpreter loaded by py2exe I could do;

ctypes.pythonapi = ctypes.PyDLL(handle_to_py2exe_interpreter)


How to fix ctypes.pythonapi?


Thanks,

Okko Willeboordse
Sakurai Youhei
2016-11-09 01:23:54 UTC
Permalink
Hello,

I have had similar problem that was _Py_PackageContext in ctypes.pythonapi.

And my workaround was to change bundle_files option to 2 which generates exe file without bundling python.dll.

The problem seems to happen when loading python.dll from memory (bundle_files=1 or 0) but time didn’t allow me to investigate more so I selected the workaround.

Best regards,
Youhei

From: Okko Willeboordse [mailto:***@gmail.com]
Sent: Tuesday, November 8, 2016 10:38 PM
To: py2exe-***@lists.sourceforge.net
Subject: [Py2exe-users] ctypes.pythonapi fails

Hello,

I run in to problems converting a PyQt4/matplotlib application in to a single executable.

matplotlib does the following;

_decref = ctypes.pythonapi.Py_DecRef

ctypes help; "pythonapi is a predefined symbol giving access to the Python C api:"

Apparently py2exe loads ctypes such that ctypes.pythonapi is not valid, since my application fails with;

File "zipextimporter.pyc", line 82, in load_module
File "matplotlib\backends\backend_qt5agg.pyc", line 31, in <module>
File "ctypes\__init__.pyc", line 375, in __getattr__
File "ctypes\__init__.pyc", line 380, in __getitem__
AttributeError: function 'Py_DecRef' not found

I can override ctypes.pythonapi before importing matplotlib as follows;

ctypes.pythonapi = ctypes.PyDLL('python%d%d.dll' % sys.version_info[:2])

With above override things work, however plain wrong since the application now has 2 interpreters (read python dll's);
one loaded by py2exe and one by the override.

If I could get a handle to the interpreter loaded by py2exe I could do;

ctypes.pythonapi = ctypes.PyDLL(handle_to_py2exe_interpreter)


How to fix ctypes.pythonapi?


Thanks,

Okko Willeboordse



________________________________

CONFIDENTIALITY NOTICE
This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information.
If you receive this message in error, please immediately delete it and all copies of it from your system, destroy any hard copies of it and notify us by email to ***@ysoft.com with a copy of this message. You must not, directly or indirectly, use, disclose, distribute, print or copy any part of this message if you are not the intended recipient. Y Soft and any of its subsidiaries each reserves the right to monitor all e-mail communications through its networks.
Y Soft is neither liable for the proper, complete transmission of the information contained in this communication nor any delay in its receipt. This email was scanned for the presence of computer viruses. In the unfortunate event of infection Y Soft does not accept liability.
Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorised to state them.
Loading...