导入错误:无法导入名称发布者

发布于 2024-10-24 09:31:22 字数 252 浏览 4 评论 0原文

我成功创建了我的应用程序的可执行版本(Py2exe、Pyinstaller)。当我尝试从 .exe 运行应用程序时,我在日志文件中收到如下错误:

Traceback(最近一次调用最后一次): 文件“CreateAS.pyw”,第 8 行,位于中 ImportError: Cannot import name Publisher

我真的被困在这部分了。你能帮我一下吗?

谢谢

I succesfully created an executable version (Py2exe, Pyinstaller) of my application. When I try to run the app from .exe, I get an error as follows in the log file:

Traceback (most recent call last):
File "CreateAS.pyw", line 8, in <module>
ImportError: cannot import name Publisher

I am really stuck in this part. Could you help me out?

Thanks

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

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

发布评论

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

评论(3

定格我的天空 2024-10-31 09:31:22

我猜测您使用的 wxPython 版本是 >= 2.8.11.0?如果是这样,则 wx.lib.pubsub 包已更改。 此页面介绍了这些更改。 wxPython 邮件列表 here 讨论了这一点。

为了使这一切在我的项目中发挥作用,我执行了此处所述的操作这是上述邮件列表线程的一部分。我总结如下:

更好的选择(即没有
黑客!)如果你能破解它(抱歉!)
是使用相同的消息传递协议
作为 v1,但在最新的 API 中,这是
称为“arg1”:

# 仅在应用程序的启动模块中   
从 wx.lib.pubsub 导入 setuparg1   
# 在所有使用 pubsub 的模块中 
从 wx.lib.pubsub 导入 pub 作为发布者

并替换任何出现的“Publisher()”。由“出版商”提供。

然后在我的 setup.py 脚本中,我必须将以下内容添加到选项中:

options = {
    "py2exe": {"packages": ['wx.lib.pubsub']}
}
setup(data_files=data_files,
      windows=[
              {'script': 'btpos.py'],
               options=options)

您现在应该能够使用新版本的 pubsub 构建可执行文件 但使用旧的API。您可能还想查看 pubsub 的新 v3 api。如果您的项目不是太大,您可能不需要做太多改变就可以过去。

I'm guessing that you are using a version of wxPython that is >= 2.8.11.0? If so, the wx.lib.pubsub package has changed. This page describes the changes. There is also a thread on the wxPython mailing list here that talks about this.

To make this all work in my project, I did the following described here which was part of the above mailing list thread. I summarize below:

The much preferable alternative (ie no
hacks!) if you can hack it (sorry!)
is to use the same messaging protocol
as v1, but in latest API, this is
called "arg1":

# only in app's startup  module   
from wx.lib.pubsub import setuparg1   
# in all modules that use pubsub 
from wx.lib.pubsub import pub as Publisher

and replace any occurence of "Publisher()." by "Publisher."

Then in my setup.py script, I had to add the following to the options:

options = {
    "py2exe": {"packages": ['wx.lib.pubsub']}
}
setup(data_files=data_files,
      windows=[
              {'script': 'btpos.py'],
               options=options)

You should now be able to build an executable using the new version of pubsub, but with the old api. You might also want to check out the new v3 api of pubsub. If your project isn't too big, you can probably get by without changing too much.

高跟鞋的旋律 2024-10-31 09:31:22

尝试这样:

from wx.lib.pubsub import setuparg1
from wx.lib.pubsub import pub as Publisher

然后:将任何出现的 Publisher() 替换为 Publisher.

try like this:

from wx.lib.pubsub import setuparg1
from wx.lib.pubsub import pub as Publisher

Then: replace any occurence ofPublisher()byPublisher.

毁我热情 2024-10-31 09:31:22

我正在使用一个使用 wx.lib.pubsub 的示例代码来研究,也遇到了这个问题。

为了简单地解决这个问题,我只是更改了这一行:

from wx.lib.pubsub import Publisher as pub

到:

from wx.lib.pubsub import pub

接受的答案具有仍然正确的链接,但为了简单起见,我添加了这个解决方案,因为接受的解决方案有点令人困惑。

I was using an example code that used wx.lib.pubsub to study from and came across this problem too.

To fix this issue simply, I just changed the line:

from wx.lib.pubsub import Publisher as pub

To:

from wx.lib.pubsub import pub

The accepted answers has links that still make it right, but for simplicity, I've added this solution because the accepted solution was a little confusing.

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