Generate python virtual environment for your project
To generate python virtual environment(venv) for your project, "cd" into your project folder and run the below command:
Syntax: python -m venv <env-name>
python -m venv myenv
Whenever you are working in your project then you have to activate your virtual environment, so that your third-party python modules which you will be installing to use in your project will be maintained in this virtual environment. To activate your venv you have to run below command:
Syntax: source <env-name>/bin/activate
cd myproject
source myenv/bin/activate
Once you complete your work for the day and now you will need to deactivate your venv run below command:
Syntax: deactivate
deactivate
Managing Packages with pip
You can install, upgrade, and remove packages using a program called pip. By default pip will install packages from the Python Package Index. You can browse the Python Package Index by going to it in your web browser.
pip has a number of subcommands: “install”, “uninstall”, “freeze”, etc. (Consult the Installing Python Modules guide for complete documentation for pip.)
Syntax: pip install requests==2.6.0
Syntax: pip list
Syntax: pip freeze > requirements.txt
Syntax: pip install -r requirements.txt
pip install requests==2.6.0
pip list
pip freeze > requirements.txt
pip install -r requirements.txt
Top comments (3)
Good job !!!
Venv + Poetry is game changer for python project
Nice