DEV Community

Dan Benitah
Dan Benitah

Posted on • Edited on

Upgrading Python version for your Microsoft Fabric environment

I was recently stuck trying to re-run a python notebook in Fabric using the Azure Event Hub package to upload data to a KQL database. The script, which had been running smoothly for months, suddenly stopped working after an environment change or update.

UPDATE: bringing forward this note as it should be a better solution to use

Note: I later found a note about my issue in some training training material, which had been my first solution without the --force parameter. That may be a better solution for you if you needed to keep the Spark Runtime unchanged https://github.com/microsoft/FabricRTA-in-a-Day/blob/main/Lab3.md#steps

The first issue I was facing was the following when installing the package in my notebook.

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed
Enter fullscreen mode Exit fullscreen mode

This error indicates that the package dependencies are conflicting, which often occurs due to Python environment version incompatibilities or misaligned dependencies.

pip's dependency resolver does not currently take into account all the packages that are installed

When trying to import the package, I could see the environment was set to 3.10 (see below).
And when trying to create my own environment, I could not find azure-eventhub pypi package either (see here).

Import issues 1

Import issues 2

Eventually, I tried to figure out how to upgrade the python environment, and with the help of a friend, I was able to do so.

Spark Runtimes

The solution was upgrade the PySpark environment.
It resolved the issue by updating the Python runtime to a compatible version with the azure-eventhub package. Switching to Spark Runtime 1.3 updated Python to version 3.11.x, resolving dependency conflicts.

How to change the Spark Runtime to 1.3

  1. Go to the Workspace settings.
    Workspace settings

  2. Select the appropriate runtime from the dropdown list.
    How to change Spark Runtime to 1.3

  3. Save and restart your notebook.

Validation of the Environment Upgrade

Now the changes have been apply, create a new notebook ensuring the selected environment uses the Spark Runtime 1.3.

# Check if the environment upgrade was successful
import azure.eventhub
print("Environment setup successful!")

Enter fullscreen mode Exit fullscreen mode

Conclusion

Upgrading the Python environment in Fabric by changing the Spark runtime resolved the dependency conflicts I faced with the azure-eventhub package. If you encounter similar issues, adjusting the runtime version can be a quick fix. Remember to validate your changes and test your script to ensure everything is working smoothly.

References:

Top comments (0)