esp官方文档:快速入门
https://docs.espressif.com/projects/esp-idf/zh_CN/stable/get-started/
按常理来说应该不会出现什么问题啊,但是确实出现了大问题。
截图如下:
更换了linux下按照官方文档运行也是出现出现了类似的问题
所以,问题到底出在哪里?
根据报错,我们可以定位subprocess.py这个自带库中的CalledProcessError()这个方法
def check_call(*popenargs, **kwargs): """Run command with arguments. Wait for command to complete. If the exit code was zero then return, otherwise raise CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute. The arguments are the same as for the Popen constructor. Example: check_call(["ls", "-l"]) """ retcode = call(*popenargs, **kwargs) if retcode: cmd = kwargs.get("args") if cmd is None: cmd = popenargs[0] raise CalledProcessError(retcode, cmd) return 0
这句话中我们清楚的看到,函数引发了一个CalledProcessEroor异常,而异常引发的原因正是无法正常结束命令的调用
我们现在回到引发异常的关键文件idf_tools.py看看他是怎么调用这个函数的
def action_install_python_env(args): idf_python_env_path, _, virtualenv_python = get_python_env_path() is_virtualenv = hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix) if is_virtualenv and (not os.path.exists(idf_python_env_path) or args.reinstall): fatal('This script was called from a virtual environment, can not create a virtual environment again') raise SystemExit(1) if args.reinstall and os.path.exists(idf_python_env_path): warn('Removing the existing Python environment in {}'.format(idf_python_env_path)) shutil.rmtree(idf_python_env_path) if not os.path.exists(virtualenv_python): info('Creating a new Python environment in {}'.format(idf_python_env_path)) try: import virtualenv # noqa: F401 except ImportError: info('Installing virtualenv') subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--user', 'virtualenv'], stdout=sys.stdout, stderr=sys.stderr) subprocess.check_call([sys.executable, '-m', 'virtualenv', idf_python_env_path], stdout=sys.stdout, stderr=sys.stderr) run_args = [virtualenv_python, '-m', 'pip', 'install', '--no-warn-script-location'] requirements_txt = os.path.join(global_idf_path, 'requirements.txt') run_args += ['-r', requirements_txt] if args.extra_wheels_dir: run_args += ['--find-links', args.extra_wheels_dir] info('Installing Python packages from {}'.format(requirements_txt)) subprocess.check_call(run_args, stdout=sys.stdout, stderr=sys.stderr)
定位到最后一句代码:
subprocess.check_call(run_args, stdout=sys.stdout, stderr=sys.stderr)
引发了异常
这里run_args是输入一串执行参数命令,对应的,就是我们平时在命令行里面输入的东西,现在python帮你完成,具体调用了什么命令行参数?
我们来看看报错信息
Traceback (most recent call last): File "/home/ssss/桌面/esp-idf/tools/idf_tools.py", line 1492, in <module> main(sys.argv[1:]) File "/home/ssss/桌面/esp-idf/tools/idf_tools.py", line 1488, in main action_func(args) File "/home/ssss/桌面/esp-idf/tools/idf_tools.py", line 1215, in action_install_python_env subprocess.check_call(run_args, stdout=sys.stdout, stderr=sys.stderr) File "/usr/lib/python2.7/subprocess.py", line 190, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['/root/.espressif/python_env/idf4.3_py2.7_env/bin/python', '-m', 'pip', 'install', '--no-warn-script-location', '-r', '/home/mastwet/\xe6\xa1\x8c\xe9\x9d\xa2/esp-idf/requirements.txt']' returned non-zero exit status 2
我们可以看到,
/home/ssss/桌面/esp-idf/tools/requirements.txt
被解析成了
'/home/mastwet/\xe6\xa1\x8c\xe9\x9d\xa2/esp-idf/requirements.txt'
所以说结论,原因是不能够将文件安放在带有中文路径的目录下!
还没结束!我发现其实windows下的报错和linux下的报错还是有区别
最后发现导致安装不上的竟然是网络问题!
最后解决方法还是老生常谈的pip换元大法
全局更新pip环境,具体可参照这篇文章