使用py2exe编译python产生错误:AttributeError:'GenericRdata'对象没有属性'target' [英] Compiling python with py2exe produces errors: AttributeError: 'GenericRdata' object has no attribute 'target'

查看:61
本文介绍了使用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的帖子中确切地确认您的打包过程是什么,但是在使用包含pymongocx_freeze打包项目时,我刚刚遇到了相同的AttributeError: 'GenericRdata' object has no attribute 'target'问题。 经过多次挖掘,似乎问题出在它没有拾取pymongodnspython依赖项,我通过在构建选项中指定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:&#39;GenericRdata&#39;对象没有属性&#39;target&#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆