简体   繁体   中英

py2exe traits GUI

I am trying do pack my program with py2exe. It uses traits GUI.
After moving the import statement in image.py in function "convert_image" out of the try block the crated exe fails at the second of the following points:

1: dist\\traitsui\\ui_traits.py: from .image.image import ImageLibrary
2: dist\\traitsui\\image\\image.py: from traitsui.ui_traits import HasBorder, HasMargin, Alignment

File Structure:

root
+-...
+-main.py
+-setup.py
+-dist
  +-...
  +-main.exe
  +-traitsui
    +-...
    +-ui_tratis.py
    +-image
      +-image.py

By adding the follow to the image.py

import sys
raise Exception(str(sys.path))

I get: Exception: ['C:\\Users...\\dist\\.']
So it seems that the path is set right.


The error trace:

Traceback (most recent call last):
  File "main.py", line 8, in <module>
  File "gui\FileSelect.pyc", line 8, in <module>
  File "traitsui\api.pyc", line 27, in <module>
  File "traitsui\basic_editor_factory.pyc", line 30, in <module>
  File "traitsui\editor_factory.pyc", line 32, in <module>
  File "traitsui\helper.pyc", line 32, in <module>
  File "C:\Users\...\dist\.\traitsui\ui_traits.py", line 158, in <module>
    from .image.image import ImageLibrary
  File "C:\Users\...\dist\.\traitsui\image\image.py", line 34, in <module>
    from traitsui.ui_traits import HasBorder, HasMargin, Alignment
ImportError: cannot import name HasBorder

setup.py: https://gist.github.com/2570888

Try adding packages: ["traitsui"] to py2exe 's options dictionary (with the skip_archive option).

I think that py2exe did not detect that the package traitsui.ui_traits is being used. You need to force it to include the whole traitsui package in the distribution.

Note: Just a guess, not tested.

hmm it seams that there was somthing wrong with the Enthought package I used for the images.

So here the new setup file which works: https://gist.github.com/2570888

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM