What Is a Virtual Environment?
At its core, the main purpose of Python virtual environments is to create an isolated environment for Python projects. This means that each project can have its own dependencies, regardless of what dependencies every other project has.
Remember do not put scripts inside virtual Enviroment
To get started, if you’re not using Python 3, you’ll want to install the virtualenv tool with pip:
#pip install virtualenvIf you are using Python 3, then you should already have the venv module from the standard library installed.
Note: From here on out, we’ll assume you’re using the newer venv tool, since there are few differences between it and virtualenv with regard to the actual commands
Create a project folder
#mkdir my-python-project
#cd my-python-projectTo check modules using pip
#pip listIf in a virtualenv that has global access, do not list globally-installed packages
#pip list --localTo check built-in modules
#python
>>>help("modules")Create virtual environment
[Python 2:]
#virtualenv project_venv[Python 3]
#python -m venv project_venv
Give the virtual environment access to the system site-packages dir
#python -m venv project_venv --system-site-packagesTo activate the virtual Environment
#project_venv\Scripts\activate.batTo check which binary is being used
#where pythonTo save the list of modules via pip
#pip3 freeze > requirements.txtTo save the list of modules via pip
#pip3 freeze --local > requirements.txtTo activate the virtual Environment
#deactivateTo remove the virtual Environment completely
#rmdir project_venv /sTo install same modules from different project from requirements.txt
First activate the virtual Environment
#pip install -r requirements.txt -vReference:
1. https://www.youtube.com/watch?v=APOPm01BVrk
for LINUX and MAC
ReplyDeletehttps://www.youtube.com/watch?v=Kg1Yvry_Ydk