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

时间:2019-01-11 00:42:54

标签: python python-3.x pyinstaller

我正在尝试使用.exe和Python 3.7.2从.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

可能是什么问题?

5 个答案:

答案 0 :(得分:9)

我找到了以下解决方案:将bindepend.py中的<myProject_path>\venv\Lib\site-packages\PyInstaller\depend替换为 Loran425 在github here

上提供的文件

答案 1 :(得分:2)

正如我从许多论坛herehere所读到的,以及有关由Pyinstaller引起的此问题的讨论一样。 如果您正在使用Pycharm或任何虚拟环境。一旦您指定了venv,Pycharm便会在interpreter路径中创建其局部垂直环境。因此,您应该将外部工具(pyinstaller)设置为python 3.7 .exe的真实路径,如图所示。 enter image description here

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

答案 2 :(得分:0)

就我而言,当我使用标准库的venv时会发生问题,而当我使用virtualenv时却不会发生。 (但是由于another bug,我不得不使用virtualenv==16.1.0。)

答案 3 :(得分:0)

该错误已在PyInstaller 3.6版中解决。只需更新就可以了。

答案 4 :(得分:0)

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

当我在name中注释掉exe时,

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时构建应用程序。