How to fix pio command not working?

I had errors all of a sudden when using VScode and PIO. I saw a message that told me to follow these instructions to upgrade to Python > v3.5 :

Drop support for Python 2 and 3.5
So after following these instructions I still see this issue:

> python --version
Python 3.9.1
PS D:\Users\Nurquhar\Documents\NuSoftLtd\Projects\RoutesReports\NR-MPV-SITT-RHTT-Jan2020\Software\RR-TTM-NR-release-build-trial> pio system info
pio : The term 'pio' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ pio system info
+ ~~~
    + CategoryInfo          : ObjectNotFound: (pio:String) [], CommandNotFoundException        
    + FullyQualifiedErrorId : CommandNotFoundException
 
PS D:\Users\Nurquhar\Documents\NuSoftLtd\Projects\RoutesReports\NR-MPV-SITT-RHTT-Jan2020\Software\RR-TTM-NR-release-build-trial>

So how to fix it so ‘pio’ command works ?

If you have installed PlatformIO extensions into VSCode, then you will not be able to see the pio or platformio commands in a shell outside of VSCode.

In addition, if you use VSCode’s Terminal->New Terminal option, the commands will not be available there either!

To use them, Click on the PlatformIo icon on the left side toolbar (Ant/Alien head), then in the Quick Access list that appears, under Miscellaneous, choose New Terminal.

Now you should be able to use the commands.

My best advice is to follow the instructions at Redirecting... to add the pio and platformio commands to your normal shell/command line sessions. That way, every terminal you open, inside or outside of VSCode, will have the commands available.

HTH

Cheers,
Norm.

5 Likes

Thanks Norm, now I get it …

pio system info


PlatformIO Core 5.1.0
Python 3.9.1-final.0
System Type windows_amd64
Platform Windows-10
File System Encoding utf-8
Locale Encoding cp1252
PlatformIO Core Directory C:\Users\Nurquhar.platformio
PlatformIO Core Executable C:\Users\Nurquhar.platformio\penv\Scripts\platformio.exe
Python Executable c:\users\nurquhar.platformio\penv\scripts\python.exe
Global Libraries 1
Development Platforms 6
Tools & Toolchains 19


PS D:\Users\Nurquhar\Documents\NuSoftLtd\Projects\RoutesReports\NR-MPV-SITT-RHTT-Jan2020\Software\RR-TTM-NR-release-build-trial>

Success! :grin:

One thing though:

Some people have had problems with Python 3.9 not working correctly. If you find any problems, try using the “portable” version of Python that PlatformIO installs when you install into VSCode.

Open VSCode, then CTRL+comma. That will take you to settings. Search for “portable” and you should find one hit: “Use a portable Python 3 interpreter if available”. Tick/check the option and PlatformIO in VSCode will use the downloaded, and known to work, version of Python 3.x instead of any external versions installed outwith VSCode.

Cheers,
Norm.

Thanks for the warning…

I have a few applications that use python so when I did a search of C:\ I found I had a dozen or more copies installed in all sorts of places. So I remove via control panel all copies I thought I had installed myself. I then installed python using the windows app store, which put the 3.9.1 on my PC where ever it liked.
When I tried installing from a python a download exe platformio could not see it, it just found my python 2.7 which I have also removed. But it could see it with the version installed from the app store. I think this hassle may be related to my PC busting through the 1024 char limit for the path variable. I tried the registry hacks to increase this but it did not seem to work.
All seems to be working for me at the moment with 3.9.1 but if I get further hassle perhaps I can downgrade to 3.8 or 3.7

For PlatformIO you shouldn’t need to downgrade the system wide version on Python, just set the option I described above to use the PlatformIO built in version. I think that’s 3.6.x at the moment. The reason I’m not sure is because on my Linux system, it has sym-linked to the 3.6.7 version that is installed system wide.

Cheers,
Norm.

Norm, you are a bloody legend mate! I have been tearing my hair out trying to figure this out. Even reinstalled windows. I wish I had seen you post earlier but thanks for posting this. Cheers.

1 Like

I’m gonna buy your book.

1 Like

I try! :wink:

That’s not a mandatory requirement! But thanks. It will be handy if you want/need to know how the Arduino works. Hope you enjoy it.

Cheers,
Norm.

I am having the same issue. I did try the above suggestions.
I am running on Ubuntu 22.04, with Python 3.10.12 installed. My default shell is zsh with .oh-my-zsh enabled. Now when I open Ubuntu Terminal, I see above python version, and PS1 prompt shows git branch when I enter any git projects.

On the other end, after installing VSC and adding platformio, when I click on “Alien” and select Miscellaneous and select eather “PlatformIO Code CLI” or “New Termina”, I see this prompt in open terminal:

wbox ➜  ecd $(git_prompt_info)

where wbox is hostname, ecd is git project I am starting to work on, and $(git_prompt_info) should be replaced with git branch, like it is in Ubuntu Terminal.

Now, if I run pio --help get not found.

wbox ➜  ecd-gps $(git_prompt_info)pio --help
zsh: command not found: pio

EDIT: Since $(git_prompt_info) is not evaluated and not sure why, there was no space above between )pio .

wbox ➜  ecd-gps $(git_prompt_info) pio --help

After I added space ) pio it works. But on next run and I remove the space, it still works. Weird.

Any one knows how to fix this $(git_prompt_info)?

Have you followed the instructions here? It appears other people have had zsh problems too.
Git_prompt_info looks like a function you need to declare in your shell, or in your zsh equivalent to .profile or .bashrc:

# Get the name of the branch we are on
git_prompt_info() {
  branch_prompt=$(__git_ps1)
  if [ -n "$branch_prompt" ]; then
    status_icon=$(git_status)
    echo $branch_prompt $status_icon
  fi
}

It would need to be globally available to have it in all zsh sessions. I note also that most of the compalins about it not working are down to __git_ps1 not being found. There are solution(s) on the page I linked.

HTH

Cheers,
Norm.