MacOS下VScode安装PlatformIO Core卡死和新建项目速度慢的解决方法
Posted SimonLiu009
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MacOS下VScode安装PlatformIO Core卡死和新建项目速度慢的解决方法相关的知识,希望对你有一定的参考价值。
最近为了折腾smartknob,尝试vscode+platformIO,安装配置遇到了不少坑,以下是解决过程。
1. PlatformIO Installer: Installing PlatformIO Core
卡死
在vscode安装PlatformIO插件之后,卡在PlatformIO Installer: Installing PlatformIO Core
大约10分钟后报错。看了开发者模式的console看不出个所以然。按照网上说的删除.platformio
或者.cache
文件夹,或者修改pip.conf
文件均没有效果。
解决方法按照官网的脚本安装方法搞定。
- 1.1 前提
终端设置科学上网代理,我的机器是本地的Clash代理export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
- 1.2 命令行下运行
python3 -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"
或者先下载这个脚本:
wget https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py
然后运行它:
python3 get-platformio.py
以下是我的安装log:
~/> python3 get-platformio.py
Installer version: 1.1.2
Platform: macOS-10.15.7
Python version: 3.9.13 (main, May 24 2022, 21:28:12)
[Clang 12.0.0 (clang-1200.0.32.29)]
Python path: /usr/local/opt/python@3.9/bin/python3.9
Creating a virtual environment at /Users/simonliu/.platformio/penv
Updating Python package manager (PIP) in a virtual environment
PIP has been successfully updated!
Virtual environment has been successfully created!
Installing PlatformIO Core
Collecting platformio
Using cached platformio-6.1.4-py3-none-any.whl
Collecting marshmallow==3.*
Using cached marshmallow-3.17.1-py3-none-any.whl (48 kB)
Collecting semantic-version==2.10.*
Using cached semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)
Collecting aiofiles==0.8.*
Using cached aiofiles-0.8.0-py3-none-any.whl (13 kB)
Collecting wsproto==1.1.*
Using cached wsproto-1.1.0-py3-none-any.whl (24 kB)
Collecting colorama
Using cached colorama-0.4.5-py2.py3-none-any.whl (16 kB)
Collecting pyserial==3.5.*
Using cached pyserial-3.5-py2.py3-none-any.whl (90 kB)
Collecting uvicorn==0.18.*
Using cached uvicorn-0.18.3-py3-none-any.whl (57 kB)
Collecting click<9,>=8.0.4
Using cached click-8.1.3-py3-none-any.whl (96 kB)
Collecting requests==2.*
Using cached requests-2.28.1-py3-none-any.whl (62 kB)
Collecting tabulate==0.8.*
Using cached tabulate-0.8.10-py3-none-any.whl (29 kB)
Collecting starlette==0.20.*
Using cached starlette-0.20.4-py3-none-any.whl (63 kB)
Collecting zeroconf<1
Using cached zeroconf-0.39.0-py3-none-any.whl (106 kB)
Collecting bottle==0.12.*
Using cached bottle-0.12.23-py3-none-any.whl (90 kB)
Collecting ajsonrpc==1.*
Using cached ajsonrpc-1.2.0-py3-none-any.whl (22 kB)
Collecting pyelftools<1,>=0.27
Using cached pyelftools-0.29-py2.py3-none-any.whl (174 kB)
Collecting packaging>=17.0
Using cached packaging-21.3-py3-none-any.whl (40 kB)
Collecting urllib3<1.27,>=1.21.1
Using cached urllib3-1.26.12-py2.py3-none-any.whl (140 kB)
Collecting certifi>=2017.4.17
Using cached certifi-2022.6.15-py3-none-any.whl (160 kB)
Collecting charset-normalizer<3,>=2
Using cached charset_normalizer-2.1.1-py3-none-any.whl (39 kB)
Collecting idna<4,>=2.5
Using cached idna-3.3-py3-none-any.whl (61 kB)
Collecting anyio<5,>=3.4.0
Using cached anyio-3.6.1-py3-none-any.whl (80 kB)
Collecting typing-extensions>=3.10.0
Using cached typing_extensions-4.3.0-py3-none-any.whl (25 kB)
Collecting h11>=0.8
Using cached h11-0.13.0-py3-none-any.whl (58 kB)
Collecting async-timeout>=4.0.1
Using cached async_timeout-4.0.2-py3-none-any.whl (5.8 kB)
Collecting ifaddr>=0.1.7
Using cached ifaddr-0.2.0-py3-none-any.whl (12 kB)
Collecting sniffio>=1.1
Using cached sniffio-1.3.0-py3-none-any.whl (10 kB)
Collecting pyparsing!=3.0.5,>=2.0.2
Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
Installing collected packages: pyserial, pyelftools, ifaddr, bottle, urllib3, typing-extensions, tabulate, sniffio, semantic-version, pyparsing, idna, h11, colorama, click, charset-normalizer, certifi, async-timeout, ajsonrpc, aiofiles, zeroconf, wsproto, uvicorn, requests, packaging, anyio, starlette, marshmallow, platformio
Successfully installed aiofiles-0.8.0 ajsonrpc-1.2.0 anyio-3.6.1 async-timeout-4.0.2 bottle-0.12.23 certifi-2022.6.15 charset-normalizer-2.1.1 click-8.1.3 colorama-0.4.5 h11-0.13.0 idna-3.3 ifaddr-0.2.0 marshmallow-3.17.1 packaging-21.3 platformio-6.1.4 pyelftools-0.29 pyparsing-3.0.9 pyserial-3.5 requests-2.28.1 semantic-version-2.10.0 sniffio-1.3.0 starlette-0.20.4 tabulate-0.8.10 typing-extensions-4.3.0 urllib3-1.26.12 uvicorn-0.18.3 wsproto-1.1.0 zeroconf-0.39.0
PlatformIO Core has been successfully installed into an isolated environment `/Users/simonliu/.platformio/penv`!
The full path to `platformio.exe` is `/Users/simonliu/.platformio/penv/bin/platformio`
If you need an access to `platformio.exe` from other applications, please install Shell Commands
(add PlatformIO Core binary directory `/Users/simonliu/.platformio/penv/bin` to the system environment PATH variable):
See https://docs.platformio.org/page/installation.html#install-shell-commands
- 1.3 更新环境变量
最后将/Users/simonliu/.platformio/penv/bin
加入PATH,在用户profile(我使用的是~/.zshrc
)中加入如下一行,并source ~/.zshrc
使他在当前终端生效。
export PATH="$PATH:/Users/simonliu/.platformio/penv/bin"
2. 新建项目太慢
以上完成后,在VSCode中新建一个项目仍然会很慢,因为系统会下载对应平台的SDK和toolchain以及Arduino框架。
以Arduino框架开发ESP32为例,解决办法仍然是通过命令行。
- 2.1 前提
仍然是终端设置科学上网代理。 - 2.2 安装相关platform sdk、toolchain和arduino framework等
#安装espressif32 sdk和toolchain等
pio platform install espressif32
# 新建一个项目文件夹
mkdir ~/Documents/PlatformIO/Projects/testproj1
cd ~/Documents/PlatformIO/Projects/testproj1
# 初始化一个nodemcu32-s board项目
pio project init --board nodemcu-32s
以下是log:
~/Documents/platformIO/Projects/testproj1> pio platform install espressif32
WARNING: This command is deprecated and will be removed in the next releases.
Please use `pio pkg install` instead.
Platform Manager: Installing espressif32
Unpacking [####################################] 100%
Platform Manager: espressif32@5.1.1 has been installed!
Tool Manager: Installing espressif/toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: toolchain-xtensa-esp32@8.4.0+2021r2-patch3 has been installed!
Tool Manager: Installing platformio/tool-esptoolpy @ ~1.30300.0
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: tool-esptoolpy@1.30300.0 has been installed!
~/Documents/platformIO/Projects/testproj1> pio project init --board nodemcu-32s
Resolving nodemcu-32s dependencies...
Tool Manager: Installing platformio/framework-arduinoespressif32 @ ~3.20004.0
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: framework-arduinoespressif32@3.20004.220825 has been installed!
Already up-to-date.
Project has been successfully updated!
完成这两个下载之后,从vscode的platformIO IDE界面新建ESP32-Arduino项目,就很快了。
如果需要其他MCU的支持,可以照此办理。
3. 查看支持的platform和boards
- 3.1 点击这里查看支持的platform
- 3.2 查看支持的board
# 查看支持的所有board列表
pio boards
#查看某个ESP32相关的board列表
pio boards esp32
注:虽然终端提示
pio platform
命令将被弃用,建议使用pio pkg install
,但是实测pio pkg install
安装会提示
以上是关于MacOS下VScode安装PlatformIO Core卡死和新建项目速度慢的解决方法的主要内容,如果未能解决你的问题,请参考以下文章
纪念首次使用vscode+platformio完成点灯全过程
使用VScode开发ESP8266,PlatformIO开发ESP8266
使用VScode开发ESP32,PlatformIO开发ESP32