Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hello,
I am trying to do a simple plot with matplotlib in a python script visual within powerbi. I have already tried installing matplotlib globally, in the directory where the pbi file is, and in the python home directory used by PowerBI. No matter how simple I make the script, I cannot use matplotlib package in any situation. Tried installing and restarting the computer and the program.
Thanks in advance for any potential solutions.
P.S. Here is a copy of the error message:
Feedback Type:
Frown (Error)
Error Message:
Python script error.
<pi>Traceback (most recent call last):
File "C:\Users\YonatanPalagashvili\PythonScriptWrapper_caa22846-a210-4728-95a3-0df80a527033\PythonScriptWrapper.PY", line 2, in <module>
import os, uuid, matplotlib
ModuleNotFoundError: No module named 'matplotlib'
</pi>
Stack Trace:
Host:Microsoft.PowerBI.Scripting.Python.Exceptions.PythonScriptRuntimeException
Traceback (most recent call last):
File "C:\Users\YonatanPalagashvili\PythonScriptWrapper_caa22846-a210-4728-95a3-0df80a527033\PythonScriptWrapper.PY", line 2, in <module>
import os, uuid, matplotlib
ModuleNotFoundError: No module named 'matplotlib'
at Microsoft.PowerBI.Scripting.Python.PythonScriptWrapper.RunScript(String originalScript, Int32 timeoutMs)
at Microsoft.PowerBI.Client.Windows.Python.PythonScriptHandler.GenerateVisual(ScriptHandlerOptions options)
--- End of inner exception stack trace ---
at Microsoft.PowerBI.Client.Windows.Python.PythonScriptHandler.GenerateVisual(ScriptHandlerOptions options)
at Microsoft.PowerBI.ExploreHost.SemanticQuery.ScriptVisualCommandFlow.RunInternal(Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
at Microsoft.PowerBI.ExploreHost.SemanticQuery.ScriptVisualCommandFlow.Run(Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.TransformDataShapeResult(QueryCommand transformCommand, SemanticQueryDataShapeCommand command, Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ExecuteDataQuery(IQueryResultDataWriter queryResultDataWriter, EngineDataModel engineDataModel, DataQuery query, Int32 queryId, ServiceErrorStatusCode& serviceErrorStatusCode, CancellationToken cancelToken)
at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ProcessAndWriteSemanticQueryCommands(IQueryResultsWriter queryResultsWriter, IList`1 queries, HashSet`1 pendingQueriesToCancel, EngineDataModel engineDataModel)
Javascript:ShowErrorDialog
at ErrorHostService.showErrorDialogCore(args)
Stack Trace Message:
Python script error.
Invocation Stack Trace:
at Microsoft.Mashup.Host.Document.ExceptionExtensions.GetCurrentInvocationStackTrace()
at Microsoft.Mashup.Client.UI.Shared.StackTraceInfo..ctor(String exceptionStackTrace, String invocationStackTrace, String exceptionMessage)
at Microsoft.PowerBI.Client.Windows.Telemetry.PowerBIUserFeedbackServices.GetStackTraceInfo(Exception e)
at Microsoft.PowerBI.Client.Windows.Telemetry.PowerBIUserFeedbackServices.ReportException(IWindowHandle activeWindow, IUIHost uiHost, FeedbackPackageInfo feedbackPackageInfo, Exception e, Boolean useGDICapture)
at Microsoft.Mashup.Client.UI.Shared.UnexpectedExceptionHandler.<>c__DisplayClass14_0.<HandleException>b__0()
at Microsoft.Mashup.Client.UI.Shared.UnexpectedExceptionHandler.HandleException(Exception e)
at Microsoft.PowerBI.Client.PowerBIUnexpectedExceptionHandler.HandleException(Exception e)
at Microsoft.PowerBI.Client.Windows.Utilities.PowerBIFormUnexpectedExceptionHandler.HandleException(Exception e)
at Microsoft.PowerBI.Client.Windows.ErrorHostService.<>c__DisplayClass6_0.<ShowErrorDialogCore>b__0()
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.WindowsFormsSynchronizationContext.Send(SendOrPostCallback d, Object state)
at Microsoft.PowerBI.Client.Windows.Services.UIBlockingService.AllowModalDialogs(Action action)
at Microsoft.PowerBI.Client.Windows.HostServiceDispatcher.<>c__DisplayClass14_0.<ExecuteOnUIThreadAndHandlePromise>b__0()
at Microsoft.PowerBI.Client.Windows.HostServiceDispatcher.ExecuteOnUIThreadAndHandlePromise[T](Func`1 func, IPromiseStore promiseStore, Int64 promiseHandle)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.PowerBI.Client.Windows.WebView2.WebView2Interop.InvokeCs(InteropCall call)
at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at Microsoft.Mashup.Client.UI.Shared.WindowManager.ShowModal[T](T dialog, Func`1 showModalFunction)
at Microsoft.PowerBI.Client.Program.<>c__DisplayClass6_0.<RunApplication>b__0()
at Microsoft.PowerBI.Client.Windows.IExceptionHandlerExtensions.<>c__DisplayClass3_0.<HandleExceptionsWithNestedTasks>b__0()
at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
at Microsoft.PowerBI.Client.Program.RunApplication(String[] args)
at Microsoft.PowerBI.Client.Program.Main(String[] args)
PowerBINonFatalError:
{"AppName":"PBIDesktop","AppVersion":"2.122.1066.0","ModuleName":null,"Component":"Microsoft.PowerBI.Scripting.Python.PythonScriptWrapper","Error":"Microsoft.PowerBI.Scripting.Python.Exceptions.PythonScriptRuntimeException","MethodDef":"RunScript","ErrorOffset":"","ErrorCode":""}
Model Default Mode:
Import
Model Version:
PowerBI_V3
Enabled Preview Features:
PBI_sparklines
PBI_scorecardVisual
PBI_NlToDax
PBI_fieldParametersSuperSwitch
PBI_setLabelOnExportPdf
PBI_dynamicFormatString
PBI_oneDriveSave
PBI_oneDriveShare
PBI_newCard
Disabled Preview Features:
PBI_shapeMapVisualEnabled
PBI_SpanishLinguisticsEnabled
PBI_qnaLiveConnect
PBI_b2bExternalDatasetSharing
PBI_enhancedTooltips
PBI_angularRls
PBI_onObject
PBI_backstageUI
PBI_gitIntegration
PBI_modelExplorer
Disabled DirectQuery Options:
TreatHanaAsRelationalSource
Cloud:
GlobalCloud
PowerBIUserFeedbackServices_IsReported:
True
Formulas:
Same error. How did you solve it?
It seems like there might be an issue with the Python environment that Power BI is using. Let's try a few troubleshooting steps to resolve the problem:
Ensure Power BI is Using the Correct Python Environment: Make sure that Power BI is using the correct Python environment where Matplotlib is installed. You can specify the Python script settings in Power BI. Follow these steps:
Check Python Path: Ensure that the Python path where Matplotlib is installed is included in the system's PATH environment variable. This can be set either globally or within the Power BI Python options.
Install Matplotlib Using Power BI's Python Environment: Open Power BI and run the following Python script in the Python script editor to install Matplotlib:
import subprocess
subprocess.check_call(["python", "-m", "pip", "install", "matplotlib"])
This script uses the Python interpreter that Power BI is configured to use. After running this script, try your Matplotlib script again.
Restart Power BI: After making changes to Python configurations or installing packages, it's a good idea to restart Power BI to ensure the changes take effect.
Use Virtual Environment (Optional): Consider using a virtual environment for your Python script within Power BI. This can help isolate dependencies and avoid conflicts.
Check Python Version Compatibility: Ensure that the version of Python installed matches the version supported by Matplotlib. You can check Matplotlib's documentation for compatibility information.
Review Security Policies: Check if there are any security policies or antivirus programs that might be blocking Power BI from accessing Python libraries. Ensure that the required permissions are granted.
Reinstall Power BI: As a last resort, if the issue persists, consider reinstalling Power BI to ensure a clean installation.
Read this blog for more about MatPlotLib:
https://analyticpulse.blogspot.com/2023/11/enhancing-power-bi-visualizations-with.html
If this helped, Subscribe AnalyticPulse on YouTube for future updates:
https://www.youtube.com/@AnalyticPulse
https://instagram.com/analytic_pulse
https://analyticpulse.blogspot.com/
Here's the official doc Run Python scripts in Power BI Desktop - Power BI | Microsoft Learn
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |
User | Count |
---|---|
10 | |
4 | |
3 | |
2 | |
2 |