Multiple Python versions on Windows

Hi πŸ‘‹

In this short article I will show you two ways of changing Python versions on Windows. It is useful when you have installed multiple Python versions on your system and want to run a specific version from the terminal.

For example, if we have the following versions installed:

We can use either the Python Launcher py to run Python or the python command.

Python Launcher

To list installed Python versions with Python launcher we can use the py -0 command.

@nutiu ➜ ~ py -0
Installed Pythons found by C:\WINDOWS\py.exe Launcher for Windows
 -3.10-64 *

@nutiu ➜ ~ py
Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

The default version has a star next to it. If we run a simple py command, we’ll get a prompt to Python 3.10. To change the default version all we need to do is to set the environment variable PY_PYTHON to the desired version.

@nutiu ➜ ~ $env:PY_PYTHON = "3.7"
@nutiu ➜ ~ py -0
Installed Pythons found by C:\WINDOWS\py.exe Launcher for Windows
 -3.7-64 *
@nutiu ➜ ~ py
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Using the Python command

If you prefer running Python using the full command then you’ll get the Python version which has higher precedence in your path, for example if I run python on my machine I will get:

@nutiu ➜ ~ python
Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

We can change the order by going to: My PC -> Advanced System Settings -> Environment Variables

Select path from User variables and click Edit…

Python 3.10 has higher precedence in path because it is above Python 3.7. If we want to change the order, we need to select the folders referencing Python37 and click Move Up until they are above Python 3.10

Restarting your terminal and running python again should run your desired Python version.

Thanks for reading! 🍻

πŸ’»Remote Desktop: logon attempt failed β›”

Hi πŸ‘‹

Have you ever tried to setup your Windows’s Remote Desktop functionality and failed with the following error message “logon attempt failed“, knowing that your credentials were correct and that you’re on the same Wi-Fi network with the computer you’re trying to access?

Well, I did.

Most of the solutions you’ll find on other blogs make you edit your Window’s registry, network settings and so on, which in my case was not needed, and it is somehow overkill.

Logging in with a password and my Microsoft account on the computer I wanted to setup Remote Desktop solved the issue.

What I had to do was to go in Settings > Accounts > Sign-in Options, disable Windows Hello PIN and all other sign in options, setup Password sign-in option and then relog on my PC.

That’s it.

Windows 11

If you’re on Windows 11 then you don’t have sign in with a password as an option. What worked for me is to reset my PIN using my Microsoft account during the login screen.

After resetting my PIN the Remote Desktop started working.

Running Linux GUI Applications in Windows

Hi πŸ‘‹,

This is a quick tutorial on how to run Linux graphical interface application in Windows using X Server’s forwarding feature.

The first step is to download and install the VcXsrv Windows X Server on your πŸ’» Windows machine.

Then, start VcXsrv with the following configuration:

Ensure that VcXsrv is not blocked in Windows Firewall, it should be allowed in Public and Private networks.

You may also use more restrictive firewal settings as explained in /wsl-windows-toolbar-launcher#firewall-rules.

The next step is to configure your Linux box.

I’m using Ubuntu in WSL 2.0 and pasting the following code into ~/.zshrc or ~/.bashrc does the trick for me. Feel free to upvote the author on SO.

# X11
HOST_IP=$(host `hostname` | grep -oP '(\s)\d+(\.\d+){3}' | tail -1 | awk '{ print $NF }' | tr -d '\r')
export DISPLAY=$HOST_IP:0.0
export NO_AT_BRIDGE=1

After that’s done, if VcXsrv is running, you should be able to open Linux GUI apps from your Terminal.

Thanks for reading! 🍺