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

  10. Als u zelf uw kind wil gaan helpen, moet u natuurlijk wel weten wat redactiesommen eigenlijk zijn. Bij redactiesommen zit de som verwerkt in een verhaal. Het worden dan ook wel verhaaltjessommen genoemd. Waar deze verhaaltjes eerst nog vrij eenvoudig en kort zijn, worden de redactiesommen in groep 8 steeds ingewikkelder.

    redactiesommen oefenen

  11. Als je een partytent huurt is het belangrijk om ook aan de aankleding en inrichting te denken. Het is wel zo praktisch om dat ook bij Colors Events te regelen. Wij kunnen behalve jouw partytent ook zorgen voor meubilair zoals statafels, al dan niet voorzien van rokken, stoelen of gewone tafels. Ook feestverlichting mag niet ontbreken als je een feest in de avonduren organiseert


  12. Webactueel schakel je in als je een maatwerk WordPress website laten maken wilt. Door een maatwerk website te ontwikkelen is het mogelijk om meer leads te genereren. Daarbij hebben we altijd oren voor de wensen en eisen die jij als ondernemer hebt als het om jouw website gaat. Bovendien gaat het om meer dan alleen een website. Ook het toepassen van de juist online marketingstrategie helpt hier in grote mate bij. Wij kunnen dit allemaal voor je verzorgen.

    Website laten maken

  13. Webactueel schakel je in als je een maatwerk WordPress website laten maken wilt. Door een maatwerk website te ontwikkelen is het mogelijk om meer leads te genereren. Daarbij hebben we altijd oren voor de wensen en eisen die jij als ondernemer hebt als het om jouw website gaat. Bovendien gaat het om meer dan alleen een website. Ook het toepassen van de juist online marketingstrategie helpt hier in grote mate bij. Wij kunnen dit allemaal voor je verzorgen.
    Lees meer

  14. Zonder al te veel poespas gewoon een nieuwe, strakke en frisse wandafwerking? Dan is het spuiten van latex muurverf een goede uitkomst. En ook dan moet je bij Latex Spuiten XXL zijn. Het hanteren van de speciale spuiten voor latexverf hebben wij ons in de loop der jaren eigen gemaakt. Door de spuittechniek ontstaat er een egale structuur, die een stuk strakker is dan bij het sauswerk met een traditionele verfroller. Bovendien is de klus een stuk sneller geklaard – ondanks dat we de werkzaamheden minstens zo gepassioneerd als traditioneel binnenschilderwerk uitvoeren. Latex spuiten is daarom doorgaans voordeliger dan latexen met de verfroller. Disclaimer: dit is afhankelijk per situatie en oppervlakte.

    muurverf spuiten

  15. Your Website is very good, Your Website impressed us a lot, We have liked your website very much.
    We have also created a website of Android App that you can see it.

  16. Blogs are very Nice.The Information's provided in the Articles about Python are useful.keep updating and visit to know more about python
    python training in chennai | python training in annanagar | python training in omr | python training in porur | python training in tambaram | python training in velachery

  17. Booty Calls Foxy Thunder Dating Most preferred trait Sexuality (red) Least preferred trait Charisma (Green) Facts Lovers Tip-friendly guests Masturbation Yes, ...


Post a Comment

Popular posts from this blog

Simple self signed TLS server and client using Twisted

Self signed TLS server and client using Twisted Prerequisites openssl twisted & pyOpenSSL modules- pip install twisted[tls] treq module - pip install treq Basic 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 pas

Embed Scrapy in WSGI Application

WSGI and Scrapy A common question on Scrapy Stackoverflow is "How to use Scrapy with Flask, Django, or any other Python web framework?" Most are used to using the Scrapy’s generated projects and cli options, which make crawling a breeze, but are confused when trying to integrate Scrapy into a WSGI web framework. A common traceback encountered is ReactorNotRestartable , which stems from the underlaying Twisted framework. This occurs because, unlike asyncio or Tornado, Twisted’s eventloop/reactor cannot be restarted once stopped (the reason is a bit out of scope). So it becomes apparent that the trick to integrating Scrapy and WSGI frameworks involves being able to tame Twisted. Luckily, integrating async Twisted code with synchronous code has become quite easy and is only getting easier. In this post, the following will be demonstrated: Embed a crawler in a WSGI app and run it using Twisted’s twist web WSGI server. Embed a crawler in a WSGI app and run it any WSGI serve