How to get PlatformIO to work through WSL? Getting no files found in UI

So I have PlatformIO installed in VS Code through WSL. I can create projects mostly fine, but what I’ve found is that PlatformIO uses \ for its paths as if it’s in a Windows filesystem. So my path ends up being something like /path/to/somewhere\project. This creates a folder that looks like somewhere\project, except for the fact that it ends up being a different weird character that creates an “invalid path” error in VS Code.

Since then, I’ve just renamed that folder, so now I can traverse into that folder in VS Code, but when I go to “Open Project” in PlatformIO home, it shows no files in that folder and says that there is no platformio.ini even though I see all the files very clearly in bash.

I’ve heard PlatformIO working well in WSL, but it has so far been very frustrating for me. Has anyone had similar issues and know how to fix it? Thanks

I wouldn’t use PlatformIO through WSL if I were you. You already encountered some problems with it. There will be more problems when you try to upload to your hardware, because WSL does not have access to the hardware drivers.

Also, how are you using WSL with vscode? Maybe there are issues with the remote extension. That could be the cause of your problems.

I also once tried to use PlatformIO through WSL, but I gave up after discovering the upload problems I’ve encountered.

I hope I could help you :smiley:

Oh that makes a lot of sense. I’ll try PlatformIO through Windows. Is there a lot of extra stuff that needs to be installed though? I’m low on space and I don’t want to have to install too many copies of all of the C/C++ dev stuff.

The used space depends on how many libraries you’ve got installed etc.
My entire PlatformIO installation needs ~1.5GB of space. Most of that space is required for the compilers for different platforms.

1 Like

If you were to run platformio directly via WSL, you’d probably be fine… but since you’re running it on top of VSCode running on Windows… you’re crossing the Windows/Linux barrier… and it’s all coming unstuck. Now, there are ways to run VSCode itself from under WSL (I think… or maybe that’s through other similar emulation layer… can’t remember now)… but that is probably harder to do than simply running PlatformIO (Core/CLI) natively. And the core itself is pretty small… it’s the compiler toolchains, and framework files that will gobble space up, but you can configure it so stuff is on a secondary drive if needed.

1 Like

Since this thread is the top Google result for “vs code platformio wsl2”… (It came up when I was first looking for solutions to this.)

VS Code and PlatformIO can be installed directly into WSL2, and it will work that way. (That’s assuming you have an Windows Insider build or have an X-Windows server running on Windows.) However, when installing VS Code, you’ll get a warning stating that the “official way” to use VS Code is under Windows and with the Remote - WSL extension.

Unfortunately, PlatformIO does not seem to be aware of the Remote - WSL extension as it currently tries to use Windows pathnames (back slashes) instead of Linux pathnames (forward slashes). There’s a year-old GitHub issue regarding this.

1 Like

:tada: Last night, I was able to compile, download the code in a board and see the serial monitor in WSL 2 and PlatformIO as a Remote - WSL extension. :tada:

It took me about ten hours to find my way, from installing Windows Insiders Preview (I wanted to see the WSL GUI apps support) to have a working system. My system isn’t stable yet and under some mysterious circumstances PlatformIO refuses to compile, but it’s already somewhat functional and I would like to register my path so someone can develop it further.

Requirements:

  • VS Code already installed on Windows
  • An existing project to test

Procedure:

  1. I installed Windows and WSL 2 with support for GUI apps as listed in this site.
  2. For USB connections, I instaled USBIP
    2.1. in Windows: using the instructions here: GitHub - cezanne/usbip-win: USB/IP for Windows
    2.2. in WLS2, using the instructions here: GitHub - rpasek/usbip-wsl2-instructions and mixing with the instructions here: Compiling Your Own Linux Kernel for Windows? WSL 2 – MicroHobby
    For the time being, both instructions are outdated, but mixing them was enough to understand the process.
  3. Using USBIP, I tried to attach a serial USB port in WSL 2. The permissions in /dev/ttyUSB0 were wrong, so I fixed them temporarily with sudo chmod 666 /dev/ttyUSB0. In the future, configuring a rule for udev should fix this permanently. I tested it with putty and had successful results.
  4. I copied the Platform IO project folder to my WSL home folder
  5. I used the Remote - WSL VS Code extension to open the project folder in my WSL home folder.
  6. In remote VS Code, I installed the Platform IO extension.

The project compiled and was downloaded in the board as expected.

To create a new project, I had to create it in Windows, then move it to WSL.

Bugs: VS Code PlatformIO extension in Windows and in WSL seem to be sharing the same folder for the frameworks and compilers, so when I switch operating systems, I have to reinstall VS Code PlatformIO extension, but that doesn’t always work. I need to investigate further.

2 Likes

I had the same problem. Did some sketchy edits to the platformio files and it worked!. Details are here : Windows WSL: I can't open any files(projects) in the PIO open browser. · Issue #2316 · platformio/platformio-home · GitHub