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

preview_player
Показать описание
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"

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

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\

Or,

E:\code\python\tvenv $ python -m virtualenv myenv
E:\code\python\tvenv $ cd myenv\Scripts

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

Or,

E:\code\python\tvenv $ py -3 -m virtualenv myenv
E:\code\python\tvenv $ cd myenv\Scripts
Рекомендации по теме