The Complete Guide to Python Virtual Environments, activate, deactivate & Requirements.txt

Published: 21 September 2022
on channel: Md. Abdullah al Mamun
575
2

When developing software with Python, a basic approach is to install Python on your machine, install all your required libraries via the terminal and write all of the source code. This works fine for simple Python scripting projects.
Implementing a complex software development project, it is required a Python interpreter, Python library, an API, or software development kit. Often you will be working with multiple files, multiple packages, dependencies, and as well as your source code. As a result, you will need to isolate your Python development environment for that particular project. This isolated environment is known as a Virtual Environment. In this tutorial, I would like to present a clear explanation of Virtual Environment and how can you implement it on your python project.

0:00 - Explain about Virtual Environment
6:30 - Check Python by CMD
7:59 - Create Virtual Environment by "virtualenv"
8:40 - Active Python Virtual Environment
9:05 - Deactive Python Virtual Environment
9:38 - Create Virtual Environment by "venv"
11:00 - Create Requirements.txt
12:05 - Install Packages by Requirements.txt



E:\code\python\tvenv $ python
print("hello")
exit()

E:\code\python\tvenv $ python [2 hipen]version

E:\code\python\tvenv $ pip [1 hipen]V
E:\code\python\tvenv $ python -m pip install --upgrade pip

E:\code\python\tvenv $ python -m pip list

E:\code\python\tvenv $ python -m venv myenv
E:\code\python\tvenv $ .\myenv\Scripts\activate.bat [CMD of windows OS ]
E:\code\python\tvenv $ .\myenv\Scripts\Activate.ps1 [PowerShell of windows OS ]
(myenv) E:\code\python\tvenv $ pip freeze [greater then] requirments.txt
(myenv) E:\code\python\tvenv $ pip install -r requirments.txt
(myenv) E:\code\python\tvenv $ .\myenv\Scripts\deactivate.bat


Uninstall virtualenv with this command.
E:\code\python\tvenv $ pip uninstall virtualenv

Then just reinstall with this command.
E:\code\python\tvenv $ pip install virtualenv

Create Virtual Environment by the 4 ways,

Solution-1: python -m venv name_of_virtual_environment
E:\code\python\tvenv $ python -m venv myenv
E:\code\python\tvenv $ cd myenv\Scripts\
E:\code\python\tvenv\myenv\Scripts $ activate.bat
(myenv) E:\code\python\tvenv\myenv\Scripts $ deactivate.bat

Or,

E:\code\python\tvenv $ python -m virtualenv myenv
E:\code\python\tvenv $ cd myenv\Scripts
E:\code\python\tvenv\myenv\Scripts $ activate.bat
(myenv) E:\code\python\tvenv\myenv\Scripts $ deactivate.bat


Solution-2: py -3 -m venv name_of_virtual_environment
E:\code\python\tvenv $ py -3 -m venv myenv
E:\code\python\tvenv $ cd myenv\Scripts
E:\code\python\tvenv\myenv\Scripts $ activate.bat
(myenv) E:\code\python\tvenv\myenv\Scripts $ deactivate.bat

Or,

E:\code\python\tvenv $ py -3 -m virtualenv myenv
E:\code\python\tvenv $ cd myenv\Scripts
E:\code\python\tvenv\myenv\Scripts $ activate.bat
(myenv) E:\code\python\tvenv\myenv\Scripts $ deactivate.bat


Watch video The Complete Guide to Python Virtual Environments, activate, deactivate & Requirements.txt online without registration, duration hours minute second in high quality. This video was added by user Md. Abdullah al Mamun 21 September 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 575 once and liked it 2 people.