MacOS下VScode安装PlatformIO Core卡死和新建项目速度慢的解决方法

16 篇文章 0 订阅
6 篇文章 0 订阅

最近为了折腾smartknob,尝试vscode+platformIO,安装配置遇到了不少坑,以下是解决过程。

1. PlatformIO Installer: Installing PlatformIO Core卡死

在vscode安装PlatformIO插件之后,卡在PlatformIO Installer: Installing PlatformIO Core大约10分钟后报错。看了开发者模式的console看不出个所以然。按照网上说的删除.platformio或者.cache文件夹,或者修改pip.conf文件均没有效果。
解决方法按照官网的脚本安装方法搞定。

  • 1.1 前提
    终端设置加速代理,例如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.1.1 前提
    仍然是终端设置代理。
  • 2.1.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的支持,可以照此办理。

2.2 方法二

浏览器配置好加速代理,然后打开PlatformIO Core CLI,在右侧打开的命令行中输入pio home,会在默认浏览器中打开PlatformIO网页版,按步骤创建所需项目即可。
在这里插入图片描述

3. 查看支持的platform和boards

# 查看支持的所有board列表
pio boards
#查看某个ESP32相关的board列表
pio boards esp32

注:虽然终端提示pio platform命令将被弃用,建议使用 pio pkg install ,但是实测pio pkg install安装会提示

  • 14
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: VSCode是一款开源的代码编辑器,PlatformIO是一个跨平台的开发工具,可以用来开发不同的嵌入式系统,包括Arduino。在VSCode中使用PlatformIO插件可以方便地进行Arduino开发。 ### 回答2: VSCode是一款开源的文本编辑器,提供了丰富的功能和扩展插件,支持多种编程语言。它可以通过安装PlatformIO插件来扩展Arduino开发的功能。PlatformIO是一个跨平台的开发工具链,可以简化Arduino项目的开发和管理。 使用VSCodePlatformIO进行Arduino开发有如下优点: 1. 开源免费:VSCodePlatformIO都是开源免费的软件,任何人都可以免费使用和参与开发,降低了开发成本。 2. 强大的编辑功能:VSCode提供了丰富的代码编辑功能,包括智能代码补全、语法高亮、格式化代码等功能,能够提高开发效率。 3. 扩展插件丰富:VSCode有大量的扩展插件可用,可以根据需求自由选择安装PlatformIO插件为Arduino开发提供了很多有用的功能,如自动下载依赖库、快速编译和上传等。 4. 跨平台支持:VSCodePlatformIO都支持多个操作系统,如Windows、MacOS和Linux,可以在不同的操作系统上进行开发和调试,提高了开发的灵活性。 5. 丰富的生态系统:PlatformIO提供了一个庞大的开源库和资源库,开发者可以方便地查找和使用各种功能模块和传感器,加速项目的开发进程。 总之,使用VSCodePlatformIO进行Arduino开发能够提供更强大的编辑功能、丰富的插件支持和跨平台的开发体验,有助于提高开发效率和项目的可维护性。 ### 回答3: VSCode PlatformIO是一款基于开源工具的开发环境,用于编写和调试Arduino项目VSCode是一个功能强大的文本编辑器,而PlatformIO则是一个跨平台的开发平台。 通过VSCode PlatformIO可以方便地编写Arduino代码,并且具有丰富的代码编辑功能,如代码自动补全、语法高亮和代码片段等,可以大大提高开发效率。 此外,VSCode PlatformIO还提供了强大的调试功能,可以方便地进行代码调试和故障排查,帮助开发者定位和解决问题。 与传统的Arduino开发环境相比,VSCode PlatformIO的优势在于其跨平台特性。它可以在不同的操作系统上运行,如Windows、Mac和Linux,而且支持多种开发板,包括不仅限于Arduino,还有ESP32、STM32等。这意味着使用VSCode PlatformIO可以更加灵活地进行开发,无需更换开发环境就可以切换不同的硬件平台。 总的来说,VSCode PlatformIO是一个集成化的开发环境,它提供了丰富的功能和强大的工具,方便开发者进行Arduino项目的编写和调试。它的跨平台特性使得开发更加灵活,能够适配多种硬件平台,是一个值得推荐的工具。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值