DEV Community

Kalpak Palekar
Kalpak Palekar

Posted on

4

Python Important

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Once you complete your work for the day and now you will need to deactivate your venv run below command:

Syntax: deactivate

deactivate
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
pip list
Enter fullscreen mode Exit fullscreen mode
pip freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (3)

Collapse
 
sc0v0ne profile image
sc0v0ne

Good job !!!

Collapse
 
untada profile image
Unknownntada

Venv + Poetry is game changer for python project

Collapse
 
blockvoltcr7 profile image
blockvoltcr7

Nice

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay