使用pyinstaller生成exe文件时发生错误-typeerror:预期的str,字节或os.PathLike对象,而不是NoneType

김남호*_*김남호 10 python pyinstaller python-3.x

我正在尝试使用Python 3.7.2 .exe.py文件构建文件pysinstaller

它适用于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
Run Code Online (Sandbox Code Playgroud)

可能是什么问题呢?

小智 16

我发现了以下解决办法:更换bindepend.py<myProject_path>\venv\Lib\site-packages\PyInstaller\depend与所提供的文件Loran425在github 这里


Sam*_*ari 2

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

对于Linux用户,请遵循我的其他答案。