https://blog.csdn.net/xiaohouzi112233/article/details/122581734
这个作者遇到的坑,我一个都不少,全部踩上了。按作者方法都顺利解决。
另外有两个作者提,但我遇到的问题,记录一下::
1、selenium打包 提示FileNotFoundError: getAttribute.js
2、打包加上--windows-disable-console 选项后闪退
selenium 问题解决方案是参考 https://github.com/Nuitka/Nuitka/issues/456
解决方案一:打包命令中添加参数 --include-package-data=selenium
解决方案二:
1、不要用 onefile 选项
2、在nuitka生成的 .dist 目录下创建 selenium\webdriver\remote目录,并把 site-packages\selenium\webdriver\remote 目录下的.js资源文件拷贝到刚才创建的目录中
其他:
把chromedriver.exe 添加到系统环境的path,或者把chromedriver.exe复制到nuitka生成的.dist目录
最终: nuitka --mingw64 --standalone --show-progress --show-memory --output-dir=out --onefile --include-package-data=selenium --plugin-enable=tk-inter --windo
ws-icon-from-ico=master0.ico xxxxxxxx.py
--windows-disable-console 闪退问题,删除print语句
---------------------------
遇到的坑
第一个坑:
Nuitka-Scons:INFO: CC 'C:\\mingw64\\bin\\gcc.exe' version check gives (8, 1, 0)
Nuitka-Scons:INFO: Initial CC: 'gcc'
Nuitka-Scons:INFO: Initial CCVERSION: (8, 1, 0)
Nuitka-Scons:INFO: Checking usability of 'C:\\mingw64\\bin\\gcc.exe' from 'gcc'
Nuitka-Scons:INFO: Too old gcc 'C:\\mingw64\\bin\\gcc.exe' ((8, 1, 0) < (11, 2)) ignored!
Nuitka-Scons:INFO: No usable C compiler, attempt fallback to winlibs gcc.
解决办法: min_version = (11, 2) 改为 min_version = (8, 1, 0)
这个可以查看虚拟环境文件夹下/Lib/site-packages/nuitka/build/SconsCompilerSettings.py,其中checkWindowsCompilerFound函数说明Remove compiler of wrong arch or too old gcc and replace with downloaded winlibs gcc,移除旧的gcc编译器(在mingw64/bin下面的gcc.exe),下载winlibs gcc编译器,但是我下载半天都没下载下来,于是修改代码,将min_version版本设置为我们的gcc.exe版本,这样下面的判断gcc_version < min_version就不满足,就不需要换别的编译器。
if compiler_path is not None:
the_cc_name = os.path.basename(compiler_path)
if isGccName(the_cc_name):
gcc_version = myDetectVersion(env, compiler_path)
min_version = (8, 1, 0)
if gcc_version is not None and (
gcc_version < min_version
or "force-winlibs-gcc" in env.experimental_flags
):
第二个坑
Nuitka-Scons:INFO: Checking if ccache is at 'C:\Users\CNXIGAO13\.conda\envs\gui\bin\ccache.exe' guessed path.
Nuitka-Scons:INFO: Checking if ccache is at 'C:\Users\CNXIGAO13\.conda\envs\gui\scripts\ccache.exe' guessed path.
Nuitka will make use of ccache to speed up repeated compilation.
Is it OK to download and put it in 'C:\Users\CNXIGAO13\AppData\Local\Nuitka\Nuitka\ccache\v3.7.12'.
No installer needed, cached, one time question.
Proceed and download? [Yes]/No
Yes
Nuitka:INFO: Downloading 'https://github.com/ccache/ccache/releases/download/v3.7.12/ccache-3.7.12-windows-32.zip'.
FATAL: Failed to download 'https://github.com/ccache/ccache/releases/download/v3.7.12/ccache-3.7.12-windows-32.zip'. Contents should manually be copied to 'C:\Users\CNXIGAO13\AppData\Local\Nuitka\Nuitka\ccache\v3.7.12\ccache-3.7.12-windows-32.zip'.
解决方法:【我输入yes回车后,下载成功,如果下载失败需手动下载,并放入指定文件夹,其他提示下载的,同理】
缺少ccache.exe,下载又失败,去github自己手动下载,按报错最后一句放到指定文件夹下(路径可能因人而异)
第三个坑: ModuleNotFoundError: No module named xxxx',例如
import SCons.Script # pylint: disable=import-error
ModuleNotFoundError: No module named 'SCons'
解决方法:缺少什么组件,就pip install xxxx
第四个坑:
File "C:\Users\ADMINI~1\AppData\Local\Temp\2\ONEFIL~1\testTkNuitka.py", line 7
, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "C:\Users\ADMINI~1\AppData\Local\Temp\2\ONEFIL~1\FwCommon.py", line 2, in
<module FwCommon>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "C:\Users\ADMINI~1\AppData\Local\Temp\2\ONEFIL~1\selenium\webdriver\__ini
t__.py", line 18, in <module selenium.webdriver>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "C:\Users\ADMINI~1\AppData\Local\Temp\2\ONEFIL~1\selenium\webdriver\firef
ox\webdriver.py", line 25, in <module selenium.webdriver.firefox.webdriver>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "C:\Users\ADMINI~1\AppData\Local\Temp\2\ONEFIL~1\selenium\webdriver\remot
e\webdriver.py", line 42, in <module selenium.webdriver.remote.webdriver>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "C:\Users\ADMINI~1\AppData\Local\Temp\2\ONEFIL~1\selenium\webdriver\remot
e\switch_to.py", line 25, in <module selenium.webdriver.remote.switch_to>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "C:\Users\ADMINI~1\AppData\Local\Temp\2\ONEFIL~1\selenium\webdriver\remot
e\webelement.py", line 37, in <module selenium.webdriver.remote.webelement>
File "C:\Users\ADMINI~1\AppData\Local\Temp\2\ONEFIL~1\pkgutil.py", line 637, i
n get_data
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\ADMINI~1\\Ap
pData\\Local\\Temp\\2\\ONEFIL~1\\selenium\\webdriver\\remote\\getAttribute.js'