How to Create Python Virtual Environments

A passionate data engineer skilled in ETL, Data warehousing, SQL, Python, Docker & Kubernetes and more. Follow my blog for tech insights!
What is a Virtual Environment?
A Python Virtual Environment is an isolated space where you can do your Python projects without mixing them up with the Python that's already installed on your computer.
Use the built-in venv module, which comes with Python 3.3 and later versions. Here's the step to create a virtual environment:
Step 1: Create a virtual environment
Open a Terminal or Command Prompt: Depending on your operating system, open a terminal or command prompt.
Navigate to the Desired Directory: Use the
cdcommand to navigate to the directory where you want to create your virtual environment. For example:cd /path/to/desired/directoryCreate the Virtual Environment: Run the following command to create a virtual environment named
myenv:python -m venv myenvReplace
myenvwith the desired name for your virtual environment.
Step 2: Activate the Virtual Environment:
Use the below command to activate the virtual environment:
myenv\Scripts\activateYou'll notice that your command prompt changes to indicate that you're now working within the virtual environment.
Install Packages (Optional): Once the virtual environment is activated, you can use
pipto install Python packages. For example:pip install package_nameDeactivate the Virtual Environment: When you're done working within the virtual environment, you can deactivate it by running the following command:
deactivate
This process creates an isolated Python environment where you can install packages independently. It's a good practice to use virtual environments for different projects to avoid conflicts between dependencies.
If you have questions or want to share your experiences, feel free to comment below. I'm here to help and engage with you.
Cheers! π


