开发者

Unable to import module

开发者 https://www.devze.com 2023-03-18 12:15 出处:网络
I\'d like to learn Python since it looks nice and I want to work with GTK.My previous experience with programming is Java and C# hardly a pain in the backside to deal with errors.However I am having p

I'd like to learn Python since it looks nice and I want to work with GTK. My previous experience with programming is Java and C# hardly a pain in the backside to deal with errors. However I am having problems with pythons py2exe and understand how to debug this problem. From what I can understand it probably a setup error relating to version types and file locations and not code.

I am running

  • Windows 7 64 bit
  • Python version 2.7.2 - 32 bit
  • pygtk-all-in-one-2.24.0.win32-py2.7
  • py2exe-0.6.9.win32-py2.7

All hyperlinks can be seen at http://pastebin.com/MNGPQVMP This is due to Stackoverflow only allowing me to post 2 links, but I've got a lot of information!

My problem is python executes my basic code fine with no problems, however using py2exe errors occur.

To produce the error I ran

python setup.py py2exe

In the list are both python files, the exe error log and the console output

  • PyApp.py > See main link
  • setup.py > See main link
  • PyApp.exe.log > See main link
  • Console output of running py2exe > See main link

For some extra information I ran

python -m py2exe.mf -d PyApp.py 
python -m py2exe.mf -d setup.py

The output of both commands are listed below

  • python -m py2exe.mf -d PyApp.py > See main link
  • python -m py2exe.mf -d setup.py > See main link

from what I can understand from the exe error log and console output is it cannot import gio (is that part of glib?). And the extra module listings indicate other errors.

The gio error from the module lising of PyApp.py points to \Python27\lib\site-packages\gtk-2.0\glib\_init_.py This file contains

enter from glib._glib import *
_PyGLib_API = _glib._PyGLib_API
del _glib here

So it looks like something could be missing. However I'm not so sure

So how do I fix this import error?

Also as a side note, Dependency Walker is also stating missing 2 windows dlls. http://localhostr.com/files/Gf1mXT3/Dependency_Walker..png I have the DLLs however they are 64 bit and not 32 bit and if i place them i开发者_运维技巧n the directory then Dependency Walker flags the 64 bit error, but at the moment its clearly not the problem.

This comes across as a popular problem but I cant seem to work out how to fix it with the information I have got.


Very easy to fix! In your setup.py file, you should have a line something like this:

options = {
                  'py2exe': {
                      'packages':'encodings',
                      'includes': '<module names>',
                  }
              },

In order to fix the error, simply add "gio" to the list of 'includes', like this:

options = {
                  'py2exe': {
                      'packages':'encodings',
                      'includes': 'gio',
                  }
              },

I have a program built in pyGTK, so I have a number of modules I have to import. Just for reference, that code looks like THIS on mine:

options = {
                  'py2exe': {
                      'packages':'encodings',
                      'includes': 'cairo, pango, pangocairo, atk, gobject, gio, subprocess',
                  }
              },
0

精彩评论

暂无评论...
验证码 换一张
取 消