In this article, I am going to show you how to use Python Virtual Environment (venv). A virtual environment is an isolated workspace for a Python project. Imagine you are working on multiple projects, and each project requires different versions of libraries. You don’t want to mess up your global Python installation. In this scenario, a Python Virtual Environment is a game changer for developers. With a virtual environment, each project can have its own dependencies and can easily run alongside other projects with different requirements on the same machine.
Let’s see how to set up a virtual environment in a Python project. For demonstration, I already opened a folder (Python project) in VS Code. Open the terminal and execute the command below:
The command “python -m venv myproj” creates a new virtual environment named myproj. The venv module is a built-in Python module. After executing this command, Python creates a new folder called myproj. Inside it, you will find a copy of the Python interpreter, a Scripts folder, and Lib/site-packages, which contains the dependencies.Now, let’s activate the virtual environment using the PowerShell script .\myproj\Scripts\Activate. When you activate a venv, it modifies your PATH and sets an environment variable (Virtual_Env)
In case you encounter the error “Activate.ps1 cannot be loaded because running scripts is disabled on this system”, it occurs because Windows sets PowerShell to Restricted by default, which prevents running any custom scripts.
To fix this issue, you have two options:
1. Temporary: This applies only to the current PowerShell session.
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
2. Permanent: If you want to avoid running the above command every time, execute the following command instead. RemoteSigned means local scripts run without restrictions.
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Once the virtual environment is activated successfully, you will see (myproj) in the terminal.
Let’s install a few libraries or dependencies in the virtual environment. For demonstration, I am installing the FastAPI framework in myproj virtual environment.To exit the virtual environment, execute the deactivate command. The deactivate command resets your original PATH variable, removes the (myproj) prefix from the terminal, and returns you to system/global Python.








Great post! Really appreciate the clarity in explaining such an important concept. For anyone interested in exploring premium real estate opportunities, I’d also love to invite you to visit Godrej Sigma 3 Greater Noida website.
ReplyDeleteThe article provides a clear practical walkthrough of Python virtual environments using venv, especially for developers managing multiple projects with different library requirements. The explanation of creating, activating, and deactivating an environment, along with the PowerShell execution-policy issue, makes the tutorial useful for beginners working with Python projects in VS Code.
DeleteThe discussion of python -m venv myproj clearly explains how Python creates an isolated project workspace with its own interpreter and package directory. For learners who want to strengthen their Python fundamentals alongside environment management, a Python Online Course can provide a structured learning path.
The section covering PowerShell activation errors is particularly helpful because it addresses a practical issue developers may encounter rather than focusing only on the normal setup process. Learners looking for a more guided approach to Python development can also explore Python Online Training to build confidence with project setup and development workflows.
DeleteThe FastAPI installation example is a useful demonstration of why isolated environments are valuable when different projects require different dependencies. Applying these concepts in hands-on development can reinforce dependency management and project organization, while Python Projects For Final Year can provide opportunities to apply Python skills in practical project scenarios.
DeleteGreat work! Love how everything is presented so clearly and beautifully.
ReplyDeleteAlso Visit - https://www.birlaestatessector71gurgaon.com/
Birla Estates Sector 71 Gurgaon is a high end housing project that features the latest 2, 3, and 4 BHK flats.
desain rumah atap miring
ReplyDeletedesain rumah atap miring ke belakang
desain rumah atap miring ke depan
desain rumah atap miring kiri kanan
desain rumah minimalis atap miring
desain rumah atap miring ke belakang minimalis
desain rumah atap miring minimalis
desain rumah atap miring samping
desain rumah minimalis atap miring sebelah
desain rumah minimalis modern atap miring