Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I am having trouble getting python visual and scripts to run in powerbi
I am trying to import the following test script as a datasource taken from the power BI documentation website https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-python-visuals
import pandas as pd
df = pd.DataFrame({ 'Fname':['Harry','Sally','Paul','Abe','June','Mike','Tom'],
'Age':[21,34,42,18,24,80,22], 'Weight': [180, 130, 200, 140, 176, 142, 210],
'Gender':['M','F','M','M','F','M','M'],
'State':['Washington','Oregon','California','Washington','Nevada','Texas','Nevada'],
'Children':[4,1,2,3,0,2,0], 'Pets':[3,2,2,5,0,1,5] })
print (df)
This gives the following error
Details: "ADO.NET: Python script error.
<pi> File "C:\Users\NirmalaD'souza\PythonScriptWrapper_fb8dadbe-f2ff-41ee-8115-53ff4a4bbbcd\PythonScriptWrapper.PY", line 9
os.chdir(u'C:/Users/NirmalaD'souza/PythonScriptWrapper_fb8dadbe-f2ff-41ee-8115-53ff4a4bbbcd')
^
SyntaxError: invalid decimal literal
</pi>"
I have python installed in the following location - C:\Program Files\Python311 and have set this as home directory in python script options
trying to run other premade scripts from online to produce visuals produces similar results
Any idea why this doesn't work?
Solved! Go to Solution.
Hi @Datalewis ,
First check the prerequisites.
Use the pip list command to check that the necessary libraries are installed. (Restart your computer after installing the library)
Ensure that you have the correct Python version and required packages installed. Power BI might be using a different Python version than the one you have installed. You can check the Python version used by Power BI Desktop under Options > Python Scripting.
I also made a simple example according to the documentation, please check if the pbix file works properly on your computer.
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
@Datalewis , Try like
import pandas as pd
import os
# Escape the single quote in the directory path
directory_path = r"C:/Users/NirmalaD\'souza/PythonScriptWrapper_fb8dadbe-f2ff-41ee-8115-53ff4a4bbbcd"
os.chdir(directory_path)
df = pd.DataFrame({
'Fname': ['Harry', 'Sally', 'Paul', 'Abe', 'June', 'Mike', 'Tom'],
'Age': [21, 34, 42, 18, 24, 80, 22],
'Weight': [180, 130, 200, 140, 176, 142, 210],
'Gender': ['M', 'F', 'M', 'M', 'F', 'M', 'M'],
'State': ['Washington', 'Oregon', 'California', 'Washington', 'Nevada', 'Texas', 'Nevada'],
'Children': [4, 1, 2, 3, 0, 2, 0],
'Pets': [3, 2, 2, 5, 0, 1, 5]
})
print(df)
Hi
Thank you for your response!!!
I tried and got the following error
Details: "ADO.NET: Python script error.
<pi> File "C:\Users\NirmalaD'souza\PythonScriptWrapper_cfa2403b-8384-422b-acbc-272ddaf1489b\PythonScriptWrapper.PY", line 9
os.chdir(u'C:/Users/NirmalaD'souza/PythonScriptWrapper_cfa2403b-8384-422b-acbc-272ddaf1489b')
^
SyntaxError: invalid decimal literal
</pi>"
To clarify, in case im trying to use the program incorrectly: my process is taking a new blank power BI project, Get Data -> More -> Other -> Python Scrpt and then copying in the code fragment
Cheers
Hi @Datalewis ,
First check the prerequisites.
Use the pip list command to check that the necessary libraries are installed. (Restart your computer after installing the library)
Ensure that you have the correct Python version and required packages installed. Power BI might be using a different Python version than the one you have installed. You can check the Python version used by Power BI Desktop under Options > Python Scripting.
I also made a simple example according to the documentation, please check if the pbix file works properly on your computer.
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
79 | |
73 | |
58 | |
36 | |
32 |
User | Count |
---|---|
90 | |
62 | |
61 | |
49 | |
45 |