How to List the Available Package in the current Python Virtual Environment

Posted on

The following article is discussing about how to list the available package in the current python virtual environment. Usually, python virtual environment is important in order to localize or to use just specific configuration or library for an example a certain python version. For more information and reference about python virtual environment, just read the article with the title ‘How to Create a Python Virtual Environment’ in this link. For an example using a specific python version for the development of an application using django framework.

In case of using django framework, there must be a specific need to use certain package. One of useful tool for managing those packages in the specific virtual environment is the ‘pip’ tool. Just use the ‘pip’ tool and execute it in the command line. There are several steps for listing the available package in the current python virtual environment. The following are the steps for achieving that purpose :

1. First of all, check the availability of the ‘pip’ tool in the operating system. Just read an article with the title of ‘How to Install pip tool for Managing Module in Ubuntu Linux 18.04’ in this link.

2. After successfully install the ‘pip’ tool, don’t forget to activate the python virtual environment. Usually, the following command is the suitable command for activating the python virtual environment :

source [python_virtual_environment_path]/bin/activate

For an example :

user@hostname:~$ source /home/user/python/django-env/bin/activate
(django-env) user@hostname:~$ 

3. After activating the python virtual environment, just execute the following command for listing the available the package in the current python virtual environment :

pip freeze

The following is the example of executing the above command in the command line :

(django-env) user@hostname:~$ pip freeze
Django==2.2.3
pkg-resources==0.0.0
psycopg2==2.7.4
psycopg2-binary==2.7.4
pytz==2019.1
sqlparse==0.3.0
(django-env) user@hostname:~$

This is suitable with the information available in the manual pages. The command attribute ‘freeze’ is useful to output installed packages in the requirements format.

Leave a Reply