Forum Discussion

smpa01's avatar
smpa01
Community Champion
1 year ago
Solved

library installation issue pyenv vs cluster-env

TLDR -

I am following this and that to install libraries. Once a library is installed, it works in the current notebook but I am unable to utilize it in any other. It seems the installed libraries are notebook-scoped than clusters-scoped. But I never had these sort of issues with requests, aiohttp and other libraries previously.

 

E.g. termcolor is installed through notebook3 and works as expected in notebook3

 

but fails in notebook4 executed shortly after

 

 

 

 

 

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi smpa01 ,

     

    You're currect, using a custom environment does introduce performance overhead:

    Library publishing takes approximately 20 minutes, as the environment needs to be built and distributed across the cluster. Session startup can take around 5 minutes, especially if the environment includes multiple or large dependencies.

    To manage this efficiently, we use hybrid approach:

    1. Use the custom environment for stable, shared libraries that are unlikely to change frequently (e.g., termcolor, numpy, pandas). This ensures consistency across notebooks without frequent rebuilds.
    2. Install fast-changing or notebook-specific libraries (like aiofiles) using %pip install in the first cell of the notebook. This avoids the need to republish the entire environment for every update.

    If this post helps, then please consider to Accept as the solution to help the other members find it more quickly and a kudos would be appreciated.

     

    Thank you.

10 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi smpa01 ,

    Thank you for reaching out Microsoft fabric community forum and providing detailed context, including links and screenshots it’s very helpful.

     

    You are correct in observing that libraries installed via %pip install is only available within the current notebook session. In Microsoft Fabric, %pip performs a session-scoped installation, which means it will not persist or carry over to other notebooks or Spark jobs, even within the same workspace.

    Libraries like requests or aiohttp may appear persistent because they are pre-installed in Fabric’s base Spark runtime.

     

    To achieve your goal of using termcolor (or any other third-party package) across multiple notebooks consistently, we recommend installing the package as a workspace library. Here’s how:

    1. Download the .whl file for termcolor from PyPI.
    2. Upload it to your workspace via OneLake or the Library Management UI.
    3. Attach it via Workspace > Libraries > Add.

    Once attached, it will be accessible to all notebooks and Spark jobs within that workspace.

     

    Hope this helps. Please reach out for further assistance.

    If this post helps, then please consider to Accept as the solution to help the other members find it more quickly and a kudos would be appreciated.

     

    Thank you.

    • smpa01's avatar
      smpa01
      Community Champion

      Can you give me a screnshot of this part

      3. Attach it via Workspace > Libraries > Add.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi smpa01 ,

         

        Here is the screenshot showing how to attach a .whl file via:

        Workspace > Libraries > Add > Custom Library

         

        As shown above, after uploading the library, make sure to click “Publish” (top right) to finalize the changes. Only then will the custom library become available across all notebooks in the workspace.

         

        Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi smpa01 ,

     

    May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

     

    Thank you.