Drekin / win-unicode-console

A Python package to enable Unicode support when running Python from Windows console.
MIT License
103 stars 12 forks source link

Py2exe compatibility #9

Closed thorstenkampe closed 9 years ago

thorstenkampe commented 9 years ago

It looks like win-unicode-console is not compatible with py2exe (see below). Is this a known issue and is there any workaround?

   import _init, docopt
  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 "F:\PortableApps\Python3x\lib\site-packages\zipextimporter.py", line 86, in load_module
    return zipimport.zipimporter.load_module(self, fullname)
  File "F:\Documents\dev\python\script\_init.py", line 5, in <module>
    try: import win_unicode_console
  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 "F:\PortableApps\Python3x\lib\site-packages\zipextimporter.py", line 86, in load_module
    return zipimport.zipimporter.load_module(self, fullname)
  File "F:\PortableApps\Python3x\lib\site-packages\win_unicode_console\__init__.py", line 2, in <module>
    from win_unicode_console import streams, console, readline_hook
  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 "F:\PortableApps\Python3x\lib\site-packages\zipextimporter.py", line 86, in load_module
    return zipimport.zipimporter.load_module(self, fullname)
  File "F:\PortableApps\Python3x\lib\site-packages\win_unicode_console\streams.py", line 4, in <module>
    from win_unicode_console.buffer import get_buffer
  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 "F:\PortableApps\Python3x\lib\site-packages\zipextimporter.py", line 86, in load_module
    return zipimport.zipimporter.load_module(self, fullname)
  File "F:\PortableApps\Python3x\lib\site-packages\win_unicode_console\buffer.py", line 8, in <module>
    PyObject_GetBuffer = pythonapi.PyObject_GetBuffer
  File "F:\PortableApps\Python3x\lib\ctypes\__init__.py", line 364, in __getattr__
    func = self.__getitem__(name)
  File "F:\PortableApps\Python3x\lib\ctypes\__init__.py", line 369, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'PyObject_GetBuffer' not found
Drekin commented 9 years ago

Could you also provide a minimal example of a script you are trying to turn into .exe? I couldn't reproduce the error. I have built .exe from the following script with no problem:

import win_unicode_console
win_unicode_console.enable()

while True:
    print(input("α> "))
thorstenkampe commented 9 years ago

It looks like the option bundle_files': 1 in setup.py causes the problem; but only with with import win_unicode_console; win_unicode_console.enable() - not for instance with import colorama; colorama.init(). For reference, here is my complete setup.py:

from distutils.core import setup
import py2exe

setup(
    console = [{'script':         'script.py',
                'icon_resources': [(0, 'resources/Python.ico')]}],
    zipfile = None,
    # http://www.py2exe.org/index.cgi/ListOfOptions
    # - equivalent to `--bundle-files 1 --compressed`
    options = {'py2exe': {'bundle_files': 1,
                          'compressed':   1
               }
    }
)
Drekin commented 9 years ago

I have no problem with bundle_files or compressed. If I call my example script echo.py, then py -m py2exe.build_exe -b 1 -c echo.py works fine.

thorstenkampe commented 9 years ago

The problem ist really "PyObject_GetBuffer = pythonapi.PyObject_GetBuffer" from buffer.py. It works in PyInstaller, without Py2exe and without 'bundle_files': 1. If it works for you then this looks like a Py2exe issue on my machine solely.

thorstenkampe commented 9 years ago

Are you running 32 or 64-bit Python?

Drekin commented 9 years ago

I have tried both 32 and 64-bit and both works. Have you tried my minimal example? And what about bundle_files=2?

thorstenkampe commented 9 years ago

It's obviously a ctypes/Py2exe issue so I"m closing this issue.