Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
johanvdk67
Regular Visitor

executing an external python script from Powerbi

I have an external python script, this runs without errors when I execute from Python:

 

 

import pandas as pd
data = [['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'],dtype=float)
print (df)

 

 

 

 

 

     Name   Age
0    Alex  10.0
1     Bob  12.0
2  Clarke  13.0

 

 

 

When executing this script from the PowerBI Python interface, no problems:

Schermafbeelding 2022-03-05 om 11.24.37.png

 

My idea is to execute this from PowerBI desktop as an external file. Why would I want that ? When the script is on my disk I can maintain it via GIT without having to copy paste the contents:

 

 

let
	PythonFile = Text.FromBinary(File.Contents("c:\git\example.py")),
	Source = Python.Execute(PythonFile)
in
	Source

 

 

 

Inspiration comes from: https://community.powerbi.com/t5/Desktop/Can-I-run-external-Python-scripts-in-Power-BI-desktop/m-p/2...

 

When doing this: I get an indentation error:

Schermafbeelding 2022-03-05 om 11.22.34.png

I find it hard to debug the error, as the PythonScriptWrapper seems to be a black box (cannot find it on disk), when I refer to a non existing file, the error will be the same.

1 ACCEPTED SOLUTION

@johanvdk67  - Okay, so the issue is not the Python step, it is the opening of the Binary file.  It must have a funny character or binary format that is confusing Power Query.

Could you open the Example.Py file in Notepad - like this - Mine is working.

DarylLynchBzy_0-1646498467383.png

 

  

View solution in original post

5 REPLIES 5
johanvdk67
Regular Visitor

Have chosen an "manual" approach via the powerquery editor, somehow I have it working now ..... Schermafbeelding 2022-03-07 om 08.21.52.pngI will try to figure out what is different and why my initial approach gave the indentation errors

johanvdk67
Regular Visitor

privacy levels: no difference

 

Text.FromBinary step: same indentation error

@johanvdk67  - Okay, so the issue is not the Python step, it is the opening of the Binary file.  It must have a funny character or binary format that is confusing Power Query.

Could you open the Example.Py file in Notepad - like this - Mine is working.

DarylLynchBzy_0-1646498467383.png

 

  

Schermafbeelding 2022-03-06 om 20.08.20.png

Daryl-Lynch-Bzy
Community Champion
Community Champion

Hi @johanvdk67 .  Have you checked the firewall settings,

DarylLynchBzy_1-1646480278061.png

 

and what does the result of the "Text.FromBinary" step look like?

let
Source = File.Contents("C:\Temp\python.py"),
Custom1 = Text.FromBinary(Source)
in
Custom1

 

DarylLynchBzy_0-1646480183094.png

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.