安装Robot Framework的Desktoplibrary时出现execfile未定义错误求助
Robot Framework安装DesktopLibrary时的execfile未定义错误解决
执行命令 pip install robotframework-desktoplibrary 时触发subprocess-exited-with-error错误,核心报错为 NameError: name 'execfile' is not defined。已尝试常规pip安装,且按指引安装了SikuliLibrary,但问题仍未解决。完整报错日志如下:
$ pip install robotframework-desktoplibrary Collecting robotframework-desktoplibrary Using cached robotframework-desktoplibrary-1.0.1.zip (15.6 MB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [17 lines of output] Traceback (most recent call last): File "C:\Users\HABLOUSHM\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module> main() File "C:\Users\HABLOUSHM\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "C:\Users\HABLOUSHM\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel return hook(config_settings) File "C:\Users\HABLOUSHM\AppData\Local\Temp\pip-build-env-pgwmj_s_\overlay\Lib\site-packages\setuptools\build_meta.py", line 341, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) File "C:\Users\HABLOUSHM\AppData\Local\Temp\pip-build-env-pgwmj_s_\overlay\Lib\site-packages\setuptools\build_meta.py", line 323, in _get_build_requires self.run_setup() File "C:\Users\HABLOUSHM\AppData\Local\Temp\pip-build-env-pgwmj_s_\overlay\Lib\site-packages\setuptools\build_meta.py", line 487, in run_setup super(_BuildMetaLegacyBackend, File "C:\Users\HABLOUSHM\AppData\Local\Temp\pip-build-env-pgwmj_s_\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in run_setup exec(code, locals()) File "<string>", line 4, in <module> NameError: name 'execfile' is not defined [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
问题原因
execfile是Python 2的内置函数,Python 3已移除该函数。而robotframework-desktoplibrary 1.0.1版本的安装脚本(setup.py)仍在使用Python 2语法,导致Python 3环境下安装失败。
解决方案
方案一:修改源码后本地安装
- 下载源码包:执行
pip download robotframework-desktoplibrary,得到robotframework-desktoplibrary-1.0.1.zip文件。 - 解压文件后进入目录,找到
setup.py,定位使用execfile的代码行,将execfile('xxx.py')替换为Python 3兼容写法:
(替换时将with open('xxx.py', 'r') as f: exec(f.read())xxx.py改为实际文件名,通常是版本信息相关文件) - 执行本地安装:在当前目录运行
pip install .
方案二:使用Python 3兼容的替代库
由于robotframework-desktoplibrary可能已停止维护,推荐更换为支持Python 3的桌面自动化库:
- SikuliXLibrary:基于SikuliX,兼容Python 3和最新Robot Framework,执行
pip install robotframework-sikulixlibrary即可安装。 - PyAutoGUI自定义关键字:通过PyAutoGUI实现桌面操作,编写Robot Framework自定义关键字调用其接口。
内容的提问来源于stack exchange,提问作者Mohamed Habloush
相关产品推荐
相关产品推荐

