msgpack / msgpack-python

MessagePack serializer implementation for Python msgpack.org[Python]
https://msgpack.org/
Other
1.92k stars 230 forks source link

Py2EXE'd application will crash when importing msgpack #166

Closed hasegaw closed 8 years ago

hasegaw commented 8 years ago

I noticed Py2EXE'd application will crash at importing msgpack.

Actually I'm still new to Python and I haven't isolated the issue perfectly. It may be an issue of Py2EXE zipimporter side, or msgpack-python.

Here is the minimum script and command line to repro the issue: https://gist.github.com/hasegaw/5bce303f5fca02140d86

Z:\hasegaw\work\msgpack\dist>test
Traceback (most recent call last):
  File "test.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\IkaLog\Python34\lib\site-packages\zipextimporter.py", line 86, in loa
d_module
    return zipimport.zipimporter.load_module(self, fullname)
  File "C:\IkaLog\Python34\lib\site-packages\msgpack\__init__.py", line 25, in <module>
    from msgpack._packer import Packer
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\IkaLog\Python34\lib\site-packages\zipextimporter.py", line 109, in load_module self.get_data)
  File "msgpack/_packer.pyx", line 9, in init msgpack._packer (msgpack/_packer.cpp:9)
SystemError: Parent module '' not loaded, cannot perform relative import

Environment:

methane commented 8 years ago

I can't understand what cause the error. But I found similar issue. http://stackoverflow.com/questions/28433559/pandas-py2exe-error-parent-module-not-loaded-cannot-perform-relative-impo

Removing "bundle_files" option may fix the issue.

methane commented 8 years ago

close issue, since no reply for a long time.

philip-x-rutkowski commented 7 years ago

I'm having the same issue. I'm not sure if this is a py2exe issue either but I was able to resolve it. This post helped: http://stackoverflow.com/questions/16981921/relative-imports-in-python-3

My environment: Python 3.4.4 on Windows py2exe 0.9.2.2 msgpack-python 0.4.8

In my msgpack installation files, instead of importing _version.py and exceptions.py in init.py and fallback.py, I placed the contents directly in these files (there is not much to copy/paste). So, as an example, change: from msgpack._version import version to: version = (0, 4, 8)

Then, right before building the executable with py2exe: set MSGPACK_PUREPYTHON=1

I'm then able to use bundle_files set to 1 in my py2exe setup script. Hopefully, this helps someone else!

methane commented 7 years ago

I don't use py2exe. Your information doesn't help me. Please post the information to somewhere else, like py2exe ML.

methane commented 7 years ago

I lock this issue to prevent noise (I receive dozen notify from github). Please file a new issue if you know clearly know what msgpack should do.