【问题标题】:An error for generating an exe file using pyinstaller - typeerror: expected str, bytes or os.PathLike object, not NoneType使用 pyinstaller 生成 exe 文件时出错 - typeerror: expected str, bytes or os.PathLike object, not NoneType
【发布时间】:2019-06-05 22:13:08
【问题描述】:

我正在尝试使用 pysinstaller 和 Python 3.7.2 从 .py 文件构建一个 .exe 文件。

它适用于 Python 3.6;然后我重新安装了最新版本的Python(3.7.2)并尝试生成一个exe文件,但是pyinstaller barfs。

以下是我得到的错误报告。

(venv) C:\Users\user\Desktop\untitled1>pyinstaller test.py

53 INFO: PyInstaller: 3.4
53 INFO: Python: 3.7.2
54 INFO: Platform: Windows-10-10.0.17134-SP0
58 INFO: wrote C:\Users\user\Desktop\untitled1\test.spec
60 INFO: UPX is not available.
61 INFO: Extending PYTHONPATH with paths
['C:\\Users\\user\\Desktop\\untitled1', 'C:\\Users\\user\\Desktop\\untitled1']
61 INFO: checking Analysis
187 INFO: checking PYZ
236 INFO: checking PKG
237 INFO: Building PKG because PKG-00.toc is non existent
238 INFO: Building PKG (CArchive) PKG-00.pkg

Traceback (most recent call last):
  File "C:\Users\user\Desktop\untitled1\venv\Scripts\pyinstaller-script.py", line 11, in  <module>
    load_entry_point('PyInstaller==3.4', 'console_scripts', 'pyinstaller')()
  File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\user\Desktop\untitled1\venv\lib\site- packages\PyInstaller\building\build_main.py", line 838, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))   
  File "C:\Users\user\Desktop\untitled1\venv\lib\site- packages\PyInstaller\building\build_main.py", line 784, in build
    exec(text, spec_namespace)
  File "<string>", line 29, in <module>   
  File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\api.py", line 424, in __init__
    strip_binaries=self.strip, upx_binaries=self.upx,   
  File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\api.py", line 196, in __init__
    self.__postinit__()
  File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()   
  File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\api.py", line 273, in assemble
    pylib_name = os.path.basename(bindepend.get_python_library_path())   
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 214, in basename
    return split(p)[1]
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 183, in split
    p = os.fspath(p) TypeError: expected str, bytes or os.PathLike object, not NoneType

可能是什么问题?

【问题讨论】:

  • 我遇到了同样的错误。你找到这个错误的答案了吗?

标签: python python-3.x pyinstaller


【解决方案1】:

我找到了以下解决方案:将&lt;myProject_path&gt;\venv\Lib\site-packages\PyInstaller\depend中的bindepend.py替换为github上Loran425提供的文件here

【讨论】:

  • 我这样做了,构建也成功了。但是从 dist 文件夹打开时,应用程序只会在打开时关闭。从 build 文件夹中打开时,显示 'my_path'/python37.dll Module not Found error 有什么解决办法吗?
  • 为我工作,谢谢。为 PyInstaller 项目提交此文件的新版本会更具可持续性
  • 它已经被提交了。它不在已发布的 PyInstaller 中,但肯定在 master 今天!
【解决方案2】:

正如我从许多论坛herehere 以及有关Pyinstaller 引起的这个问题的讨论中读到的。 如果您使用的是 Pycharm 或任何虚拟环境。不幸的是,一旦您指定interpreter,Pycharm 就会在venvpath 中创建其本地虚拟环境。因此,您应该将外部工具(pyinstaller)设置为您的 python 3.7 .exe 的真实路径,如图所示。

Linux 用户请关注我的其他回答here

【讨论】:

  • 工作目录就是你的项目存放的目录吧?
  • @KunjMehta 正确,它也是您项目所有导入库的存储目录。
【解决方案3】:

在我的情况下,当我使用标准库的 venv 时会出现问题,但在使用 virtualenv 时不会出现问题。 (但是因为another bug,我不得不使用virtualenv==16.1.0。)

【讨论】:

    【解决方案4】:

    该错误已在 PyInstaller 3.6 版中得到解决。只需更新即可正常工作。

    【讨论】:

    • 我必须删除 uuid 才能升级到 3.5 以上。 uuid 现在是内置的,但由于 python 2 的兼容性,一些包会将其安装为 req。
    【解决方案5】:

    它可能来自格式错误的规范文件,就像注释或缺少参数一样简单(但很难找到)。

    当我在exe 中注释掉name 时,

    exe = EXE(pyz,
              a.scripts,
              a.binaries,
              a.zipfiles,
              a.datas,
              [],
              # name='my_app',
              debug=False,
              bootloader_ignore_signals=False,
              strip=False,
              upx=True,
              upx_exclude=[],
              runtime_tmpdir=None,
              console=True,
              icon='resources/icons/icon.ico',
              version='resources/version/version.py')
    

    我得到以下回溯:

    146666 INFO: Building PYZ (ZlibArchive) c:\projects\my-env\app\qc\tools\my_app\build\my_app_old\PYZ-00.pyz completed successfully.
    Traceback (most recent call last):
      File "C:\Users\lorem\Anaconda3\envs\my-env\Scripts\pyinstaller-script.py", line 10, in <module>
        sys.exit(run())
      File "C:\Users\lorem\Anaconda3\envs\my-env\lib\site-packages\PyInstaller\__main__.py", line 114, in run
        run_build(pyi_config, spec_file, **vars(args))
      File "C:\Users\lorem\Anaconda3\envs\my-env\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
        PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
      File "C:\Users\lorem\Anaconda3\envs\my-env\lib\site-packages\PyInstaller\building\build_main.py", line 720, in main
        build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
      File "C:\Users\lorem\Anaconda3\envs\my-env\lib\site-packages\PyInstaller\building\build_main.py", line 667, in build
        exec(code, spec_namespace)
      File "my_app_old.spec", line 49, in <module>
        version='resources/version/version.py')
      File "C:\Users\lorem\Anaconda3\envs\my-env\lib\site-packages\PyInstaller\building\api.py", line 382, in __init__
        self.name = os.path.join(CONF['distpath'], os.path.basename(self.name))
      File "C:\Users\lorem\Anaconda3\envs\my-env\lib\ntpath.py", line 214, in basename
        return split(p)[1]
      File "C:\Users\lorem\Anaconda3\envs\my-env\lib\ntpath.py", line 183, in split
        p = os.fspath(p)
    TypeError: expected str, bytes or os.PathLike object, not NoneType
    

    应用程序在包含name 时构建。

    【讨论】:

      猜你喜欢
      • 2020-11-07
      • 2021-09-12
      • 1970-01-01
      • 1970-01-01
      • 2021-11-07
      • 1970-01-01
      • 2018-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多