Search code examples
pythonazuredatabricksazure-databricksgraphframes

ImportError: No module named 'graphframes' databricks


I am trying to import graphframes in to my databricks notebook

    from graphframes import *     

but failed with following error message

ImportError: No module named 'graphframes'

How can I add/import in to databricks notebook, any help appreciated.


Solution

  • Note: By default, "graphframes" is not installed on the databricks.

    You need to install the package explicitly.

    You can install the packages in different methods.

    Method1: Installing external packages using pip cmdlet.

    Syntax: %sh /databricks/python3/bin/pip install <packagename>

    %sh
    /databricks/python3/bin/pip install graphframes
    

    enter image description here

    Method2: Using Databricks library utilities

    Syntax:

    dbutils.library.installPyPI("pypipackage", version="version", repo="repo", extras="extras")
    dbutils.library.restartPython()  # Removes Python state, but some libraries might not work without calling this function
    

    To install graphframes using databricks library utilities use the below command.

    dbutils.library.installPyPI("graphframes") 
    

    enter image description here

    Tried the examples available in this article GraphFrames Documentation.

    Notebook output:

    enter image description here

    Hope this helps.