Compiling python with py2exe produces errors: AttributeError: #39;GenericRdata#39; object has no attribute #39;target#39;(使用py2exe编译python产生错误:AttributeError:#39;GenericRdata#39;对象没有属性#39;target#39;)
本文介绍了使用py2exe编译python产生错误:AttributeError:';GenericRdata';对象没有属性';target';的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Python3源文件集合(其中一个名为event
的源文件是Cython化的),我正尝试使用setup.py
中的以下安装脚本将其转换为main.exe
:
setup(
name="event",
cmdclass={"build_ext": build_ext},
ext_modules=ext_modules,
windows=[{'script': 'main.py'}],
)
我尝试打开main.exe
时遇到的错误有:
Traceback (most recent call last):
File "main.py", line 6, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "mongo.pyc", line 9, in <module>
File "pymongomongo_client.pyc", line 639, in __init__
File "pymongouri_parser.pyc", line 500, in parse_uri
File "pymongosrv_resolver.pyc", line 102, in get_hosts
File "pymongosrv_resolver.pyc", line 86, in _get_srv_response_and_hosts
File "pymongosrv_resolver.pyc", line 87, in <listcomp>
AttributeError: 'GenericRdata' object has no attribute 'target'
我曾考虑将我所有的.py文件转换为.c,然后使用MSVC编译为exe,但不确定这里是否正确修复。
有人见过这个吗?
非常感谢您提前回复!
推荐答案
在操作员的问题之后有点晚,但只是为了以防万一仍然需要这样做,并在将来省去其他任何人的麻烦:
我不能从OP的帖子中确切地确认您的打包过程是什么,但是在使用包含pymongo
的cx_freeze
打包项目时,我刚刚遇到了相同的AttributeError: 'GenericRdata' object has no attribute 'target'
问题。
经过多次挖掘,似乎问题出在它没有拾取pymongo
的dnspython
依赖项,我通过在构建选项中指定dns
修复了这个问题:
build_exe_options = {
"packages": ["dns"],
"excludes": ["tkinter"],
}
base = "Console"
setup(
name="demo",
version="0.0.0",
description="demo exe",
options={"build_exe": build_exe_options},
executables=[
Executable(
"demo.py",
base=base,
)
]
)
我没有使用其他打包程序(py2exe、PyInstaller等)测试过这一点,但是如果它们有相同的问题,这可能是相同的根本原因。
这篇关于使用py2exe编译python产生错误:AttributeError:';GenericRdata';对象没有属性';target';的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:使用py2exe编译python产生错误:AttributeError:';GenericRdata';对象没有属性';target';
基础教程推荐
猜你喜欢
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01