Create a Portable Python 3.10 Virtual Environment on Windows

Python 3.10 is the latest version of the Python language, and it offers many new features and enhancements. If you want to use portable Python 3.10 on your Microsoft Windows computer, you can create a portable virtual environment. This will allow you to run Python 3.10 without having to install it on your computer. In this blog post, we will show you how to create a portable Python 3.10 virtual environment on Windows. You can use those methods on Python 3.x versions prior to 3.10, such as 3.8 and 3.9.

What is Python language?

Python is a widely used high-level interpreted programming language created in December 1989 by Guido van Rossum with a design philosophy entitled, “There’s only one way to do it, and that’s why it works.” Python syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports multiple paradigms including structured (particularly procedural), object-oriented, and functional programming. Python is often described as a “batteries included” language due to its comprehensive standard library.

What are the benefits of Python?

Python is easy to learn for beginners and has many modules and libraries that allow for robust programming. Python is used in many application domains including web development, scientific computing, artificial intelligence, and software engineering. Python is also popular as a scripting language. Python scripts can be used to automate tasks on your computer or server.

What is a Python Virtual Environment?

A Python virtual environment is an isolated development environment that allows you to install Python packages without affecting other Python installations on your system. A virtual environment allows you to manage Python dependencies for your projects. Virtual environments are also useful for development and testing purposes.

Why you should consider creating portable a virtual environment?

There are several reasons why you might want to create a portable Python virtual environment.

– You can use Python without having to install it on your computer. This is especially useful if you don’t have administrator privileges on your computer.

– A portable Python virtual environment is self-contained and isolated from the rest of your system. This means that you can install Python packages without affecting the rest of your system.

– You can easily share a portable Python virtual environment with others.

How to create a portable Python 3.10 virtual environment on windows?

Creating a portable Python virtual environment for Windows is super easy. Follow these steps to create a portable Python environment on Windows.

Step 1: Create basic Python installer

1. First, download the version of your choice the Python Windows embeddable package from here.

2. Extract downloaded Python version into eg. C:\_python\Python_310

3. Download the Python script, from https://bootstrap.pypa.io/get-pip.py and save the Python file in the Python folder

get pip

4. Open a terminal/command prompt, cd to the folder containing the get-pip.py file, and run:

python get-pip.py
python get-pip.py

5. Edit pythonxxx._pth (eg. python310._pth) and enter below:

Lib/site-packages
python310.zip 
.

# Uncomment to run site.main() automatically
import site
python310._pth

6. Install Python virtualenv:

python -m pip install virtualenv
pip install virtualenv

7. Create a DLLs folder in the Python directory

portable python - DLLs folder

Step 2: Create a virtual environment for the project.

1. Create project folder eg. C:\_python\SampleProject

2. In Command Prompt, go to the directory where you installed Python in the previous step.

3. To create a virtual environment in your new created project folder use the below command

python -m virtualenv C:\_python\SampleProject\venv
virtualenv

4. From the Python folder copy python310.zip to the Scripts folder in your project virtual environment

python310.zip

5. Your environment is prepared to execute Python scripts.

Step3: Activate Python environment

1. Navigate in Command Prompt to your project folder

2 . Activate Python environment by running the below code

venv\Scripts\activate
Activate python environme

3. If you don’t have Python installed on your system, use the direct path to python.exe instead.

venv\Scripts\python.exe hello.py
execute python script

Step 4: Install packages

1. Activate the virtual environment

2. Manually install packages such as pandas using pip install eg. pip install pandas

pip install

3. If you have a requirements.txt file in your project folder, you may use the following command

pip install -r requirements.txt

4. To list which packages have been installed, use the command

pip freeze
pip freeze

What is the best way to utilize Python portable?

You may copy your project folder to a flash drive after you’ve completed the tasks outlined above. Repeat the previous procedure but with the activation and execution of Python scripts.

portable python example

Because no Python is installed on the system, the project’s Python version appears as shown in the screenshot above.

Conclusion

Creating a Python 3.10 virtual environment on Windows is easy and can be done in just a few steps. A Python virtual environments allow you to install Python packages without affecting other Python installations on your system. Virtual environments are also useful for development and testing purposes. Activating and using Python virtual environments is also easy to do. In addition, Python packages can be installed manually or with the help of a requirements file. Finally, you can share your project’s Python virtual environment folder with others by copying it to a USB drive.