How to Install Python PIP on Debian

Posted on July 31, 2019 at 11:54 am

To manage Python packages you can use PIP.

To install PIP just type:

apt-get install python-pip  #python 2
apt-get install python-pip3 #python 3

Here is an example on how to use PIP:

pip install packageName
pip uninstall packageName
pip search packageName

For example, to install dnspython module:

root@server ~ # pip install dnspython
Collecting dnspython
  Downloading https://files.pythonhosted.org/packages/ec/d3/3aa0e7213ef72b8585747aa0e271a9523e713813b9a20177ebe1e939deb0/dnspython-1.16.0-py2.py3-none-any.whl (188kB)
    100% |████████████████████████████████| 194kB 2.6MB/s
Installing collected packages: dnspython
Successfully installed dnspython-1.16.0

Here is an example on how to import a module in a script:

#!/usr/bin/python
 
import dns.resolver
 
myResolver = dns.resolver.Resolver()
myResolver.nameservers = ['8.8.8.8', '8.8.4.4']
 
try:
        myAnswers = myResolver.query("google.com", "A")
        for rdata in myAnswers:
                print rdata
except:
        print "Query failed"

Updated on August 5, 2019 at 11:03 pm

Receive updates via email

Other Posts

Updated Posts