記一次安裝ESP32開發環境:ESP-IDF安裝配置的排坑之旅
阿新 • • 發佈:2020-08-10
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環境,具體可參照這篇文章