Skip to main content

Python alias commands that play nice with virtualenv

There are plenty of predefined Python executables, symlinks, and aliases that come bundled with your operating system. These commands come in very handy because it saves you from typing out long commands or chain of scripts. However the downfall of operating system aliases is that they don’t always play nice with virtualenv (or venv if you’re on Python 3). Most predefined aliases use the system’s default Python as the interpreter, which is next to useless when your application runs in a virtual environment. Over the years, I’ve come up with my own Python aliases that play nice with virtual environments. For this post, I tried to stay as generic as possible such that any alias here can be used by every Pythonista. In other words, there will be no aliases for specific frameworks such as running a Django server or starting a Scrappy spider. The following is one of my bash scripts I source:


#----- Pip -----#
alias pip-list="pip freeze | less"
alias pip-search="pip freeze | grep -i"
alias pip-remove="pip uninstall"
alias pip-upgrade="pip install -U"
alias pip-upgrade-all="pip freeze --local | grep -v '^\-e' | cut -d = -f 1|xargs -n1 pip install -U"

#----- Debugging -----#
alias pdb="python -m pdb"
alias ppjson="python -m json.tool"
alias module-locate="python -c 'from imp import find_module;from sys import argv;print(find_module(argv[1])[1])'"

#----- Documentation -----#
alias pydoc="python -m pydoc"


This set of commands is the most convenient because pip can be a bit awkward when installing, uninstalling, and upgrading modules. Astute dev-ops folks might notice that I took heavy inspiration from tools like apt-get and yum. These commands also imitate conda, so for those who are using Anaconda, checkout conda out.

  • pip-list: List all installed modules then pipe to a cursor so that it’s easy to scroll.
  • pip-search: Search installed Python modules
  • pip-remove: Uninstall Python module(s)
  • pip-upgrade: Upgrade Python module(s)
  • pip-upgrade-all: My favorite for development. Upgrades all the Python packages without the need to specifying them individually.


  • pdb: This is self explanatory for veterans. Runs scripts in the environment’s Python debugger.
  • ppjson: Pretty print JSON from a file or curl output. If you work with JSON and RESTful web apps, then you need this!
  • module-locate: Locate the system file path to a particular Python module, which can be useful when debugging. This is actually a script on my machine, but to keep this post brief, I did a quick one-liner to capture the gist of my script.

Let's do a quick tutorial of ppjson. I generally use this to test JSON responses from web apps in conjunction with curl, treq, and/or requests. For example, lets get some Star Wars JSON from SWAPI and pipe it to our new ppjson alias:

curl -L | ppjson
      "name": "Luke Skywalker",
      "height": "1.72 m",
      "mass": "77 Kg",
      "hair_color": "Blond",
      "skin_color": "Caucasian",
      "eye_color": "Blue",
      "birth_year": "19 BBY",
      "gender": "Male",
      "homeworld": "",
      "films": [
      "species": [
      "vehicles": [
      "starships": [
      "created": "2014-12-09T13:50:51.644000Z",
      "edited": "2014-12-10T13:52:43.172000Z",
      "url": ""

ppjson also works with files containing JSON.


  • pydoc: Reference the environment PyDocs. This is generally very helpful (despite the HTML pages looking very ugly) when you need to get documentation of a module in your virutalenv. I regularly start the web server so that I can quickly reference builtin and installed modules without the need to google. Example: pydoc -b -p 9001


  1. For a simple version of module-locate:

    $ pip install e
    $ python -me pytest

    Literally 'python me' this 'python me' that!

  2. Here are some shortcuts, which I find extremely helpful:

    function pylib() {
    "$BROWSER" "$1.html"

    function pylib2() {
    "$BROWSER" "$1.html"

    function pypi() {
    "$BROWSER" "$1"

    (I usually have set BROWSER to "xdg-open".)

  3. I really appreciate information shared above. It’s of great help.

    python online training india

  4. I was very much confused what to do next in my career, but after going through this article I got a clear version of undergoing Python Training in Chennai| Python Course in Chennai

  5. Your post is really awesome. Your blog is really helpful for me to develop my skills in a right way. Thanks for sharing this unique information with us.
    - Learn Digital Academy

  6. This information really amazing thanks for share this article thank you..

    good morning shayari

  7. The bright color makes it visible even from the high distance which is a plus point in case of emergency

    TOP 10 Best SOTs

  8. Really i found this article more informative, thanks for sharing this article! Also Check here

    Download and install Vidmate App which is the best HD video downloader software available for Android. Get free latest HD movies, songs, and your favorite TV shows

    Vidmate App Download

    Vidmate apk for Android devices

    Vidmate App

    download Vidmate for Windows PC

    download Vidmate for Windows PC Free

    Vidmate Download for Windows 10

    Download Vidmate for iOS

    Download Vidmate for Blackberry

    Vidmate For IOS and Blackberry OS

  9. It takes less than 7 minutes to sign up for our Instagram bot and set up your first promotion. Automate your social media marketing by following 3 simple steps:

    free instagram followers instant


Post a Comment

Popular posts from this blog

Simple self signed TLS server and client using Twisted

Self signed TLS server and client using TwistedPrerequisitesopenssltwisted & pyOpenSSL modules- pip install twisted[tls]treq module - pip install treqBasic knowledge of Twisted TCP servers/clients
Generate self signed certificate Generate the server's private key using a secret, which is SuperSecretPassword in this case. openssl genrsa -aes256 -passout pass:SuperSecretPassword -out server.key 2048 Perform a CSR (certificate signing request). Ensure the FQDN (fully qualified domain name) matches the hostname of the server, otherwise the server won't be properly validated. openssl req -new -key server.key -passin pass:SuperSecretPassword -out server.csr # Common Name (e.g. server FQDN or YOUR name) []:localhost openssl x509 -req -passin pass:SuperSecretPassword -days 1024 -in server.csr -signkey server.key -out server.crt For development purposes, remove the password from the certificate. openssl rsa -in server.key -out server_no_pass.key -passin pass:SuperSecretPassword mv…

Twisted Klein: Database Usage

twisted.enterprise.adbapi Twisted, and subsequently Klein, allows asynchronous interaction with databases using blocking/sequential interfaces using adbapi. The only caveat is that the database interface must be DBAPI 2.0 compliant. For instance, if a PostgreSQL database needs to be accessed, then a typical interaction would be something like:

importpsycopg2connection=psycopg2.connect(database='Tutorial',user='admin',host='')cursor=connection.cursor()cursor.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);")cursor.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100,"mydata"))cursor.execute("SELECT * FROM test;")connection.commit()cursor.close()connection.close()
Depending on environment settings, connecting to the database server, inserting data, or even querying for records can take an unpredictable amount of time, which can cause your application to slow down considerab…