Run Python on the Go

How to Run a Custom Version of Python on Windows without Administrative Access

As a Python developer, I often receive questions about how to run a custom version of Python on a Windows machine without administrative access. In this blog post, I will detail the steps to download and install a portable version of Python on Windows, update the PATH environment variable, and install dependencies using pip.

Step 1: Download Python

To start, head to the official Python download page and click on the appropriate link for your version of Python (in this case, Python 3.x). Once the download is complete, extract the contents of the .zip file to a folder.

Step 2: Delete the _pth File

Before we can use the portable version of Python, we need to delete the file ending in ._pth. The exact name changes depending on the Python release you have downloaded, but in general, it will be in the form python3XX._pth, where XX will be the same digits from above. This file is used by Python to locate modules on Windows.

Step 3: Update the PATH Environment Variable

Now that Python is downloaded and prepared, we need to update the PATH environment variable. When you type a command into the command prompt (e.g., python), the command line interpreter will search all of the directories listed in PATH (semicolon-separated on Windows, colon-separated on Linux and macOS) to find that executable. This is also used by Python to locate modules on Windows.

To update the PATH variable, follow these steps:

a. Right-click on Computer or This PC (depending on your version of Windows) and select Properties.

b. In the Properties window, click on Advanced system settings.

c. In the System Properties window, click on Environment Variables.

d. In the Environment Variaries window, click on the New button.

e. Enter the name of the environment variable as PATH, and the value as the path to your Python executable (e.g., C:UsersYourUsernamePython38python.exe).

f. Click OK to save the changes.

Step 4: Install Dependencies Using pip

Now that we have set up the portable version of Python, we need to install any dependencies our code needs using pip. To do this, execute the following command:

pip –no-index –no-binary :all:

This command will install all available packages, including any dependencies required by your code.

Conclusion

In this blog post, we have covered how to download and install a portable version of Python on Windows, update the PATH environment variable, and install dependencies using pip. Please remember that if you are on a shared computer, you should be mindful of disk space usage and put your copy of portable Python on a USB flash drive, or otherwise delete it when you’re done. Additionally, keep your portable Python installation up to date by regularly checking the Python website for security updates.

Alternative methods for those with administrative access include package managers such as chocolately and scoop. If you have any questions or comments, please feel free to leave them below. I will do my best to respond promptly.

Leave a Reply