【问题标题】:Compiling a python script with Pyinstaller via terminal通过终端使用 Pyinstaller 编译 python 脚本
【发布时间】:2018-05-03 16:16:45
【问题描述】:

我正在使用 macOS 和 Anaconda 3 来管理我的库和编写脚本。

我想为我的脚本创建一个可执行文件。

我在终端中使用 Pyinstaller 运行命令:

pyinstaller --onefile /Directory/file.py

但是,终端返回此错误:

File "/anaconda3/lib/python3.6/site-packages/PyInstaller/hooks/hook-sysconfig.py", line 42, in <module> hiddenimports = [sysconfig._get_sysconfigdata_name()] TypeError: _get_sysconfigdata_name() missing 1 required positional argument: 'check_exists'

我该如何解决这个问题;谢谢您的帮助。

【问题讨论】:

    标签: python terminal executable pyinstaller


    【解决方案1】:

    conda update conda 对我不起作用,所以我将在此处发布我的解决方案。

    首先,进入python交互shell,做

    $ python
    >> import sysconfig
    >> print(sysconfig.__file__)
    

    这应该为您提供sysconfig 的文件所在位置。然后你需要去那个文件并编辑源代码,对我来说是/opt/conda/envs/test/lib/python3.6/sysconfig.py,然后找到_get_sysconfigdata_name的函数并更改函数签名,我所做的就是让check_exists默认为True

    【讨论】:

      【解决方案2】:

      这是旧版 Anaconda 中的一个已知问题。您可以尝试更新 Anaconda(在 conda 终端中):

      conda update conda
      

      您也可以尝试从 .spec 文件中的 hiddenimports 列表中删除 sysconfig._get_sysconfigdata_name(),然后在 .py 文件中添加 import sysconfig

      pyinstaller github 页面上的以下问题文档可能会提供进一步的帮助: https://github.com/pyinstaller/pyinstaller/issues/3192

      【讨论】:

        猜你喜欢
        • 2019-03-02
        • 1970-01-01
        • 1970-01-01
        • 2019-09-08
        • 2023-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-24
        相关资源
        最近更新 更多