python - 使用 py2exe 编译 python 会产生错误:AttributeError: 'GenericRdata' object has no attribute 'target'
问题描述
我有一组 Python 3 源文件(其中一个名为event
cythonized),我正在尝试main.exe
使用以下设置脚本将其转换为setup.py
:
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 "pymongo\mongo_client.pyc", line 639, in __init__
File "pymongo\uri_parser.pyc", line 500, in parse_uri
File "pymongo\srv_resolver.pyc", line 102, in get_hosts
File "pymongo\srv_resolver.pyc", line 86, in _get_srv_response_and_hosts
File "pymongo\srv_resolver.pyc", line 87, in <listcomp>
AttributeError: 'GenericRdata' object has no attribute 'target'
我考虑过将所有 .py 文件转换为 .c,然后使用 MSVC 将其编译为 exe,但不确定这是正确的解决方法。
有没有人遇到过这个?
非常感谢您提前回复!
解决方案
在OP的问题之后有点晚了,但以防万一这仍然需要,并在未来为其他人省去麻烦:
我无法从 OP 的帖子中确切确认您的打包过程是什么,但我在使用which containsAttributeError: 'GenericRdata' object has no attribute 'target'
打包项目时遇到了同样的问题。经过大量挖掘,似乎问题在于它没有获取' 的依赖项,我通过在构建选项中指定来修复它:cx_freeze
pymongo
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 等)对此进行测试,但如果他们有同样的问题,这可能是相同的根本原因。
推荐阅读
- spring - 需要通过读取属性文件来创建bean列表
- unit-testing - 如何使用命令行上的“kotlin.test”依赖项进行编译?
- php - 为什么什么都没有出现?拉拉维尔 8?
- javascript - ngFor 在响应式轮播中将项目相互叠加
- google-apps-script - 不相关的范围干扰其他范围的值
- laravel - 为什么我的队列事件延迟不起作用
- python - 我无法向 mysql 添加新数据,但我可以操作现有(导入的)数据
- php - WordPress rest api 使用自定义类型发布
- html - 角度反应形式 - 无效输入上的样式字段颜色
- python - 仅当在单独的文件中给出转换命令时,才能将 HTML 转换为 PDF