How to install new python package using PIP

Introduction

In this tutorial, How to Setup a Python Virtual Environment. I will Install New Python package for the test environment.

In the preview post, I have installed and configured basic PIP here

Activate Your Virtual Environment

source venv/bin/activate

You can see “(venv)” indicator at the beginning of your command prompt.

(Test_Environment) [devopsroles@server1 ~]$

At any time, you can stop your virtual environment using the deactivate command.

(Test_Environment) [devopsroles@server1 ~]$ deactivate
[devopsroles@server1 ~]$ 

Install new python package using PIP

Install Packages

[devopsroles@server1 ~]$ pip3 freeze > package.txt
[devopsroles@server1 ~]$ python3 -m venv Test_Environment
[devopsroles@server1 ~]$ source Test_Environment/bin/activate
(Test_Environment) [devopsroles@server1 ~]$ pip install flask==1.0.0
(Test_Environment) [devopsroles@server1 ~]$ pip freeze > package_after.txt

After, install flask package in Test_Environmet as below

(Test_Environment) [devopsroles@server1 ~]$ ll
total 8
-rw-rw-r--. 1 devopsroles devopsroles  93 Sep  3 21:21 package_after.txt
-rw-rw-r--. 1 devopsroles devopsroles 297 Sep  3 21:20 package.txt
drwxrwxr-x. 5 devopsroles devopsroles 100 Sep  3 21:21 Test_Environment

You can difference confirmation as the picture below

How to install new python package using PIP

Now, you can install everything package for another developer could easily recreate your environment and run code

git clone https://github.com/username/devopsroles.git
cd /home/huupv
source venv/bin/activate
pip install -r requirements.txt

Conclusion

You can install a new python package using PIP for a Virtual environment. I hope will this your helpful. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.