导入错误:无法导入名称发布者
我成功创建了我的应用程序的可执行版本(Py2exe、Pyinstaller)。当我尝试从 .exe 运行应用程序时,我在日志文件中收到如下错误:
Traceback(最近一次调用最后一次): 文件“CreateAS.pyw”,第 8 行,位于
我真的被困在这部分了。你能帮我一下吗?
谢谢
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜测您使用的 wxPython 版本是
>= 2.8.11.0?如果是这样,则
wx.lib.pubsub
包已更改。 此页面介绍了这些更改。 wxPython 邮件列表 here 讨论了这一点。为了使这一切在我的项目中发挥作用,我执行了此处所述的操作这是上述邮件列表线程的一部分。我总结如下:
然后在我的 setup.py 脚本中,我必须将以下内容添加到选项中:
您现在应该能够使用新版本的 pubsub 构建可执行文件 但使用旧的API。您可能还想查看 pubsub 的新 v3 api。如果您的项目不是太大,您可能不需要做太多改变就可以过去。
I'm guessing that you are using a version of wxPython that is
>= 2.8.11.0
? If so, thewx.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:
Then in my
setup.py
script, I had to add the following to the 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.
尝试这样:
然后:将任何出现的
Publisher()
替换为Publisher.
try like this:
Then: replace any occurence of
Publisher()
byPublisher.
我正在使用一个使用 wx.lib.pubsub 的示例代码来研究,也遇到了这个问题。
为了简单地解决这个问题,我只是更改了这一行:
到:
接受的答案具有仍然正确的链接,但为了简单起见,我添加了这个解决方案,因为接受的解决方案有点令人困惑。
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:
To:
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.