在pyinstaller打包时出现如下错误,很明显感觉是路径被转义 或者历史迁移导致的
报错路径:OSError: [WinError 123] 文件名、目录名或卷标语法不正确。: D:\t_job\x07naconda3_20201121\\Lib\\site-packages'
安装路径:File "D:\11_job\anaconda3_20201121\
(base) H:\资料整理-222\pyMyproject\001模块验证\pyinstall验证>pyinstaller -c -F create_file.py
7043 INFO: PyInstaller: 6.1.0
7044 INFO: Python: 3.8.5 (conda)
7045 INFO: Platform: Windows-7-6.1.7601-SP1
7049 INFO: wrote H:\资料整理-222\pyMyproject\001模块验证\pyinstall验证\create_file.spec
my yiyyyyyyyy H:\资料整理-222\pyMyproject\001模块验证\pyinstall验证\create_file.spec H:\资料整理-222\pyMyproject\001模块验证\pyinstall验证\dist H:\资料整理-222\pyMyproject\001模块验
证\pyinstall验证\build False
7077 INFO: Extending PYTHONPATH with paths
['H:\\资料整理-222']
8230 INFO: checking Analysis
8231 INFO: Building Analysis because Analysis-00.toc is non existent
8232 INFO: Initializing module dependency graph...
8233 INFO: Caching module graph hooks...
8304 INFO: Analyzing base_library.zip ...
24462 INFO: Loading module hook 'hook-heapq.py' from 'D:\\11_job\\anaconda3_20201121\\lib\\site-packages\\PyInstaller\\hooks'...
25148 INFO: Loading module hook 'hook-encodings.py' from 'D:\\11_job\\anaconda3_20201121\\lib\\site-packages\\PyInstaller\\hooks'...
36409 INFO: Loading module hook 'hook-pickle.py' from 'D:\\11_job\\anaconda3_20201121\\lib\\site-packages\\PyInstaller\\hooks'...
38155 INFO: Caching module dependency graph...
38587 INFO: Running Analysis Analysis-00.toc
38587 INFO: Looking for Python shared library...
38621 INFO: Using Python shared library: D:\11_job\anaconda3_20201121\python38.dll
38638 INFO: Analyzing H:\资料整理-222\pyMyproject\001模块验证\pyinstall验证\create_file.py
38643 INFO: Processing module hooks...
38667 INFO: Looking for ctypes DLLs
38687 INFO: Analyzing run-time hooks ...
38699 INFO: Looking for dynamic libraries
39017 INFO: Extra DLL search directories (AddDllDirectory): []
39017 INFO: Extra DLL search directories (PATH): []
my orig_paths::: ['D:\\11_job\\anaconda3_20201121', 'D:\\11_job\\anaconda3_20201121\\lib\\site-packages', 'D:\t_job\x07naconda3_20201121\\Lib\\site-packages']
Traceback (most recent call last):
File "D:\11_job\anaconda3_20201121\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\11_job\anaconda3_20201121\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\11_job\anaconda3_20201121\Scripts\pyinstaller.exe\__main__.py", line 7, in
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\__main__.py", line 205, in _console_script_run
run()
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\__main__.py", line 189, in run
run_build(pyi_config, spec_file, **vars(args))
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\__main__.py", line 61, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\building\build_main.py", line 1043, in main
build(specfile, distpath, workpath, clean_build)
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\building\build_main.py", line 982, in build
exec(code, spec_namespace)
File "H:\资料整理-222\pyMyproject\001模块验证\pyinstall验证\create_file.spec", line 4, in
a = Analysis(
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\building\build_main.py", line 468, in __init__
self.__postinit__()
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\building\datastruct.py", line 184, in __postinit__
self.assemble()
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\building\build_main.py", line 800, in assemble
self.binaries.extend(find_binary_dependencies(self.binaries, collected_packages))
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\building\build_main.py", line 232, in find_binary_dependencies
return bindepend.binary_dependency_analysis(binaries, search_paths=extra_libdirs)
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in binary_dependency_analysis
parent_dir_preservation_paths = _get_paths_for_parent_directory_preservation()
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\depend\bindepend.py", line 74, in _get_paths_for_parent_directory_preservation
print('my orig_paths list:::',[pathlib.Path(path).resolve() for path in orig_paths])
File "D:\11_job\anaconda3_20201121\lib\site-packages\PyInstaller\depend\bindepend.py", line 74, in
print('my orig_paths list:::',[pathlib.Path(path).resolve() for path in orig_paths])
File "D:\11_job\anaconda3_20201121\lib\pathlib.py", line 1177, in resolve
s = self._flavour.resolve(self, strict=strict)
File "D:\11_job\anaconda3_20201121\lib\pathlib.py", line 205, in resolve
s = self._ext_to_normal(_getfinalpathname(s))
OSError: [WinError 123] 文件名、目录名或卷标语法不正确。: 'D:\t_job\x07naconda3_20201121\\Lib\\site-packages'
根据报错路径,找到path的变量位置,修改源码,打印path 确认问题点,因为pyinstaller是安装程序不能debug(print是debug的另一种形式)
pathlib.Path(path).resolve() for path in orig_paths
发现是 site.getusersitepackages() 返回影响,进一步查询,找到如下的位置,配置了USER_SITE的环境变量,在字符串前面加上r表示不转义 ,即可解决;
附注,除了 \11 还有\a(naconda) 也进行了转义