无法导入模块

发布于 2024-11-18 16:45:06 字数 1694 浏览 14 评论 0原文

我想学习Python,因为它看起来不错并且我想使用GTK。我以前的编程经验是 Java 和 C#,在处理错误方面几乎不是什么痛苦的事情。不过,我在使用 python py2exe 时遇到问题,并且了解如何调试此问题。据我所知,这可能是与版本类型和文件位置而不是代码相关的设置错误。

我正在运行

  • Windows 7 64 位
  • Python 版本 2.7.2 - 32 位
  • pygtk-all-in-one-2.24.0.win32-py2.7
  • py2exe-0.6.9.win32-py2.7

所有超链接都可以见 http://pastebin.com/MNGPQVMP 这是由于 Stackoverflow 只允许我发布 2 个链接,但我有很多信息!

我的问题是 python执行我的基本代码没有问题,但是使用 py2exe 会出现错误。

为了产生错误,我运行了

python setup.py py2exe

列表中的两个 python 文件、exe 错误日志和控制台输出

  • PyApp.py >参见主链接
  • setup.py >请参阅主链接
  • PyApp.exe.log >请参阅主链接
  • 运行 py2exe 的控制台输出>请参阅主链接

有关我运行的一些额外信息

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

下面列出了两个命令的输出

  • python -m py2exe.mf -d PyApp.py >参见主链接
  • python -m py2exe.mf -d setup.py > 从我可以从 exe 错误日志和控制台输出中了解到的内容中查看主链接

,它无法导入 gio(是 glib 的一部分吗?)。额外的模块列表指示其他错误。

PyApp.py 模块列表中的 gio 错误指向 \Python27\lib\site-packages\gtk-2.0\glib\_init_.py 该文件包含

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

所以看起来可能是丢失的。不过我不太确定

那么我该如何修复这个导入错误?

另外作为旁注,Dependency Walker 还指出缺少 2 个 windows dll。 http://localhostr.com/files/Gf1mXT3/Dependency_Walker..png 我有 DLL,但它们是 64 位而不是 32 位,如果我将它们放在目录中,则 Dependency Walker 会标记 64 位错误,但目前它显然不是问题。

这是一个普遍存在的问题,但我似乎无法用我所掌握的信息来解决它。

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 in 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉生梦死 2024-11-25 16:45:06

非常容易修复!在你的 setup.py 文件中,你应该有这样一行:

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

为了修复错误,只需将“gio”添加到“包含”列表中,如下所示:

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

我有一个程序内置于 pyGTK,因此我必须导入许多模块。仅供参考,该代码在我的代码中看起来像这样:

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

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',
                  }
              },
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文