Skip to main content

Visualizing python project dependencies

When you install python packages using pip, it remembers the dependency tree of installed packages. Together with Graphviz, pipdeptree can generate a nice visualization of python project dependencies.

What is even better is – It allows to save the output in a user friendly format such as jpeg, png or pdf.

How to use it on Windows 10 PC

  • Download Graphviz from this link
                http://www.graphviz.org/download/
  • Add below to PATH environment variable (Update the installed graphviz version if needed)     
       C:\Program Files (x86)\Graphviz2.38\bin 
       C:\Program Files (x86)\Graphviz2.38\bin\dot.exe
  • Close any open command prompt, restart it and navigate to your python project folder. e.g.,      
          cd C:\Projects\GitHub\Installer_Bootstrapper
  • Install ‘pipdeptree’ and ‘graphviz’ python libraries   
       pip install pipdeptree
       pip install graphviz
  • Now you can start testing 'pipdeptree'
    • View dependency tree of all installed packages 
                 pipdeptree
    • View dependency tree of a particular packages - django
          pipdeptree -p django
    • View reverse dependency tree 
                 pipdeptree -r

  • Now, let’s visualize it as jpeg image using GraphViz 
        pipdeptree --graph-output jpeg > out.jpeg
        
         or, render dependency graph as a pdf file 

        pipdeptree --graph-output pdf > out.pdf
        
This is how the generated image looked like 🙌🙌


Comments

Popular posts from this blog

Solving PyCharm bug: "Python helpers are not copied yet..."

I have been using PyCharm Professional to run and debug Python code from my Windows machine to a remote Linux device. There are some other tools available for the same purpose (e.g. Python Tool for Visual Studio 2017). But in my opinion, PyCharm Professional stands out among its counterparts as it comes with a "All Batteries Included" setup. Once you configure remote Python interpreter in PyCharm, then it works out of the box. However, today after upgrading to PyCharm Professional 2018.2.1, I could not run my Python script on remote device. The execution always failed with below error - "Error running 'hello': Python helpers are not copied yet to the remote host. Please wait until remote interpreter initialization finishes." To solve this issue, I had to remove the ".pycharm_helpers " folder from the remove device and then restart PyCharm so that the folder is re-created and files are copied again. Here are the steps with comma...

Customized Crosshair with OxyPlot charting library

I am using Oxyplot to draw heatmap for a WPF project and needed to draw a crosshair that moves according to user clicks. Since I couldn't find any good example or documentation on the topic, I made a small hack by using LineAnnotations and by over-riding Oxyplot mouse click event. Here is the sample code using WPF with MVVM pattern- MainWindow.xaml <Grid>         <oxy:Plot x:Name="CrossHairPlot">             <oxy:Plot.Axes>                 <oxy:LinearAxis Key="MyXAxis" Position="Bottom" IsZoomEnabled="False"/>                 <oxy:LinearAxis Key="MyYAxis" Position="Left" IsZoomEnabled="False"/>                 <oxy:LinearColorAxis Key="...

Generating settings.SECRET_KEY in django

On some occasions, there might be a need to generate a random Secret key for your Django project. The easiest option could be starting a django shell and running the below command - from django.core.management. utils import get_random_secret_key get_random_secret_key () However, this may not be safe to use in a production environment. A better option is to use a defined a set of allowed characters including upper case letters and then use Django to generate a long key. Here is an example of it - a. Define a list of allowed characters lower_plus_numbers = ( list ( chr (o) for o in range ( 0x61 , 0x7B )) + list ( chr (o) for o in range ( 0x30 , 0x3A ))) punctuation = list ( '!@#$%^&*(-_=+)' ) upper_alpha = list ( chr (o) for o in range ( 0x41 , 0x5B )) b. Generate Secret Key from django.utils.crypto import get_random_string key_length = 60 get_random_string( key_length, allowed_chars=lower_plus_numbers + punctuation + upper_alpha, ) c...