PyInstaller: 'TypeErrorを解決します:NoneTypeではなくstr、bytesまたはos.PathLikeオブジェクトが必要です'問題



Pyinstaller Solvetypeerror



PyInstallerでPython3.7.2および3.4​​を使用すると、「TypeError:予期されるstr、bytes、またはos.PathLikeオブジェクト、NoneTypeではない」エラーが発生します。解決策は、venv/Lib/site-packages/PyInstaller/depend/bindepend.pyファイルを直接変更して追加することです。

if is_win and 'VERSION.dll' in dlls: pydll = 'python%d%d.dll' % sys.version_info[:2] if pydll in PYDYLIB_NAMES: filename = getfullnameof(pydll) return filename

機能するget_python_library_path内部では、変更されたコンテンツは次のとおりです。



def get_python_library_path(): ''' Find dynamic Python library that will be bundled with frozen executable. NOTOE: This is a fallback option when Python library is probably linked statically with the Python executable and we need to search more for it. On Debian/Ubuntu this is the case. Return full path to Python dynamic library or None when not found. We need to know name of the Python dynamic library for the bootloader. Bootloader has to know what library to load and not trying to guess. Some linux distributions (e.g. debian-based) statically build the Python executable to the libpython, so bindepend doesn't include it in its output. In this situation let's try to find it. Darwin custom builds could possibly also have non-framework style libraries, so this method also checks for that variant as well. ''' # Try to get Python library name from the Python executable. It assumes that Python # library is not statically linked. dlls = getImports(sys.executable) for filename in dlls: for name in PYDYLIB_NAMES: if os.path.basename(filename) == name: # On Windows filename is just like 'python27.dll'. Convert it # to absolute path. if is_win and not os.path.isabs(filename): filename = getfullnameof(filename) # Python library found. Return absolute path to it. return filename # Python library NOT found. Resume searching using alternative methods. # Applies only to non Windows platforms. if is_win and 'VERSION.dll' in dlls: pydll = 'python%d%d.dll' % sys.version_info[:2] if pydll in PYDYLIB_NAMES: filename = getfullnameof(pydll) return filename if is_unix: for name in PYDYLIB_NAMES: python_libname = findLibrary(name) if python_libname: return python_libname elif is_darwin: # On MacPython, Analysis.assemble is able to find the libpython with # no additional help, asking for sys.executable dependencies. # However, this fails on system python, because the shared library # is not listed as a dependency of the binary (most probably it's # opened at runtime using some dlopen trickery). # This happens on Mac OS X when Python is compiled as Framework. # Python compiled as Framework contains same values in sys.prefix # and exec_prefix. That's why we can use just sys.prefix. # In virtualenv PyInstaller is not able to find Python library. # We need special care for this case. # Anaconda places the python library in the lib directory, so # we search this one as well. prefixes = [compat.base_prefix, os.path.join(compat.base_prefix, 'lib')] for prefix in prefixes: for name in PYDYLIB_NAMES: full_path = os.path.join(prefix, name) if os.path.exists(full_path): return full_path # Python library NOT found. Return just None. return None
  1. https://github.com/Loran425/pyinstaller/commit/14b6e65642e4b07a4358bab278019a48dedf7460
  2. https://stackoverflow.com/questions/54138898/an-error-for-generate-an-exe-file-using-pyinstaller-typeerror-expected-str