Thursday, January 28, 2021

Struggling to install Python in Windows 10

Today, I tried to install Python 3.9.1 on Windows 10. And wasted around 3 hours of time...

Let's not talk about what didn't work.

I am going to focus on how to get it running.

First is to download the latest version of Python from the Python website. Then, install it. But do a custom install. Install Python for all users (requires administrator rights) so that it will be install in your "Program Files" folder. Add it to the path too. There is the "Enable Win32 long paths" too, allow that (requires administrator rights too). That is part one.

Then, install the required tools.
python -m pip install --upgrade pip setuptools wheel
 
Install the virtualenv package so that you can set up virtual environments.
python -m pip install virtualenv

Finally, for EVERY project, set up its own virtual environment by going into the project folder, then:
virtualenv venv
This will create a virtual environment in a subfolder named venv. To activate the virtual environment, from the project folder:
venv\Scripts\activate

Once the virtual environment has been activated, you can install other requirements using pip, such as
pip install -r requirements.txt
or
pip install pysimplegui

I know this takes up a lot of space because you are duplicating the packages for each project, but I think it will help when you need to actually package your apps, because every project is more or less self-contained.
 
For VSCode, you can then use Ctrl+Shift+P to bring up the command palette, then Python: Select Interpreter to choose the interpreter for each project. You should choose the interpreter for the virtual environment of your project. To run the file, you should click on the "Play" button at the top right corner of the editor. Or see "Environments and Terminal windows" to set up the proper terminal.

Helpful links:

No comments: