# Invoke Pythod Method Error

**URL:** <https://forum.uipath.com/t/invoke-pythod-method-error/393809>\
**Category:** Activities\
**Tags:** activities-panel, datatable, question, studio, python, orchestrator, excel, activities\
**Created:** [January 25, 2022, 5:13am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809 "2022-01-25T05:13:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yudhisteer\_Chintaram1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yudhisteer_chintaram1/32/308433_2.png) [@Yudhisteer\_Chintaram1](https://forum.uipath.com/u/Yudhisteer_Chintaram1)\
**Post date:** [January 25, 2022, 5:13am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/1 "2022-01-25T05:13:29Z")

</div>

Hello,

I have a script whereby I read an excel with pandas as a Dataframe and then I write the excel again as shown below:

 ![image](https://global.discourse-cdn.com/uipath/original/4X/4/e/8/4e851ff218b4c4a7c1a8a67c1e4600064b26d688.png)

My only input parameter is the file name noted with the variable “file”.

When I run the script in PyCharm it works fine but when run in UiPath I have an Invoke Python Method: One or more errors occurred.

 ![image](https://global.discourse-cdn.com/uipath/original/4X/6/1/f/61f75d3e5e9f5f6b6b8b98b117dfef61159f4de0.png)

What shall I do? Thanks for the help!

---

<div class="post-metadata">

**Author:** ![GouthamVijay](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gouthamvijay/32/221103_2.png) [@GouthamVijay](https://forum.uipath.com/u/GouthamVijay)\
**Post date:** [January 25, 2022, 6:01am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/2 "2022-01-25T06:01:45Z")

</div>

@Yudhisteer_Chintaram1

Can you type the warning message from UiPath?!

---

<div class="post-metadata">

**Author:** ![Yudhisteer\_Chintaram1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yudhisteer_chintaram1/32/308433_2.png) [@Yudhisteer\_Chintaram1](https://forum.uipath.com/u/Yudhisteer_Chintaram1)\
**Post date:** [January 25, 2022, 6:08am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/3 "2022-01-25T06:08:29Z")

</div>

Only this: Invoke Python Method: One or more errors occurred.

---

<div class="post-metadata">

**Author:** ![GouthamVijay](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gouthamvijay/32/221103_2.png) [@GouthamVijay](https://forum.uipath.com/u/GouthamVijay)\
**Post date:** [January 25, 2022, 6:09am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/4 "2022-01-25T06:09:59Z")

</div>

You can refer the following example…  
[PythonActivitiesTest.zip](https://forum.uipath.com/uploads/short-url/dFVWpryIvNX1GDvxOwmS8iL3E6s.zip) (2.5 KB)

---

<div class="post-metadata">

**Author:** ![Yudhisteer\_Chintaram1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yudhisteer_chintaram1/32/308433_2.png) [@Yudhisteer\_Chintaram1](https://forum.uipath.com/u/Yudhisteer_Chintaram1)\
**Post date:** [January 25, 2022, 7:39am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/5 "2022-01-25T07:39:19Z")

</div>

For other function it is working properly. For example this code to square numbers. It runs in UiPath.

![image](https://global.discourse-cdn.com/uipath/original/4X/9/0/0/90038f774756513dfb093ea2b0089edd5477d6a4.png)

But to write an excel, this one is not working.

---

<div class="post-metadata">

**Author:** ![GouthamVijay](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gouthamvijay/32/221103_2.png) [@GouthamVijay](https://forum.uipath.com/u/GouthamVijay)\
**Post date:** [January 25, 2022, 7:47am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/6 "2022-01-25T07:47:12Z")

</div>

The output data-type you can change in the properties of “Get Python Object”, and then you can use write cell Activity.

---

<div class="post-metadata">

**Author:** ![Yudhisteer\_Chintaram1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yudhisteer_chintaram1/32/308433_2.png) [@Yudhisteer\_Chintaram1](https://forum.uipath.com/u/Yudhisteer_Chintaram1)\
**Post date:** [January 25, 2022, 9:08am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/7 "2022-01-25T09:08:31Z")

</div>

No. The python object already write the excel. I just want to run the python file.

---

<div class="post-metadata">

**Author:** ![supermanPunch](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/supermanpunch/32/133652_2.png) [@supermanPunch](https://forum.uipath.com/u/supermanPunch)\
**Post date:** [January 25, 2022, 9:14am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/8 "2022-01-25T09:14:08Z")

</div>

> [@Yudhisteer\_Chintaram1](#):
>
> ![image](https://global.discourse-cdn.com/uipath/original/4X/4/e/8/4e851ff218b4c4a7c1a8a67c1e4600064b26d688.png)
> 
> image956×368 24.9 KB

Hi @Yudhisteer_Chintaram1 , Could you place the first two Import lines inside the function and test it.  
Also assuming that the file assignment is not being used when used in UiPath. If used, please delete the file assignment line as well.

Let us know if this doesn’t work or if you get a different kind of error.

---

<div class="post-metadata">

**Author:** ![GouthamVijay](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gouthamvijay/32/221103_2.png) [@GouthamVijay](https://forum.uipath.com/u/GouthamVijay)\
**Post date:** [January 25, 2022, 9:15am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/9 "2022-01-25T09:15:44Z")

</div>

Remove func(file) and try once…

---

<div class="post-metadata">

**Author:** ![Yudhisteer\_Chintaram1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yudhisteer_chintaram1/32/308433_2.png) [@Yudhisteer\_Chintaram1](https://forum.uipath.com/u/Yudhisteer_Chintaram1)\
**Post date:** [January 25, 2022, 10:45am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/10 "2022-01-25T10:45:20Z")

</div>

Nopes. Doesn’t work.  
Same kind of issue.

 ![image](https://global.discourse-cdn.com/uipath/original/4X/c/a/1/ca174ac31cf2a3a80d7662b03dac2170f2fe6bd0.png)

---

<div class="post-metadata">

**Author:** ![Yudhisteer\_Chintaram1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yudhisteer_chintaram1/32/308433_2.png) [@Yudhisteer\_Chintaram1](https://forum.uipath.com/u/Yudhisteer_Chintaram1)\
**Post date:** [January 25, 2022, 10:45am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/11 "2022-01-25T10:45:34Z")

</div>

Still doesn’t work

---

<div class="post-metadata">

**Author:** ![ptrobot](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ptrobot/32/175001_2.png) [@ptrobot](https://forum.uipath.com/u/ptrobot)\
**Post date:** [January 25, 2022, 10:59am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/12 "2022-01-25T10:59:17Z")

</div>

Test to change your **file\_path** variable. Remove r and replace with double backslashes. Or change them to forward slashes.

E.g.

```auto
file_path = "C:\\Test\\gym.xls"

```

or

```auto
file_path = "C:/Test/gym.xls"

```

---

<div class="post-metadata">

**Author:** ![Yudhisteer\_Chintaram1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yudhisteer_chintaram1/32/308433_2.png) [@Yudhisteer\_Chintaram1](https://forum.uipath.com/u/Yudhisteer_Chintaram1)\
**Post date:** [January 25, 2022, 11:44am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/13 "2022-01-25T11:44:54Z")

</div>

Nopes. Neither solution works.

---

<div class="post-metadata">

**Author:** ![supermanPunch](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/supermanpunch/32/133652_2.png) [@supermanPunch](https://forum.uipath.com/u/supermanPunch)\
**Post date:** [January 25, 2022, 11:53am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/14 "2022-01-25T11:53:12Z")

</div>

@Yudhisteer_Chintaram1 ,

Could you Provide us the Code Snippet in a Text File or use the Ctrl + E to add the Code Snippet in the Preformatted text.

> [@Yudhisteer\_Chintaram1](#):
>
> ![image](https://global.discourse-cdn.com/uipath/original/4X/c/a/1/ca174ac31cf2a3a80d7662b03dac2170f2fe6bd0.png)
> 
> image928×338 18.5 KB

Also, we do see the file path assignment has been deleted, but the imports are not moved inside the function. Have we tested it by moving the imports inside the function?

---

<div class="post-metadata">

**Author:** ![Yudhisteer\_Chintaram1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yudhisteer_chintaram1/32/308433_2.png) [@Yudhisteer\_Chintaram1](https://forum.uipath.com/u/Yudhisteer_Chintaram1)\
**Post date:** [January 25, 2022, 12:07pm UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/15 "2022-01-25T12:07:01Z")

</div>

```auto
import pandas as pd
import numpy as np

def func(file):

    df = pd.read_excel(file)
    print(df.head)
    df.to_excel("output.xlsx",sheet_name='Country', index = False)
    x = "Good"
    return x

```

Yes. I tried with the imports inside the function and it still does not work.

---

<div class="post-metadata">

**Author:** ![ptrobot](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ptrobot/32/175001_2.png) [@ptrobot](https://forum.uipath.com/u/ptrobot)\
**Post date:** [January 25, 2022, 12:40pm UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/16 "2022-01-25T12:40:55Z")

</div>

Could you share your workflow also? I just tested your Python code on my computer and it’s working fine.

![image](https://global.discourse-cdn.com/uipath/original/4X/f/3/c/f3c41d4b109d6cd43d377ce938fe5e591720f359.png)

![image](https://global.discourse-cdn.com/uipath/original/4X/9/f/f/9ff0771004e5892db0a04acaf09a68f103c968f8.png)

![image](https://global.discourse-cdn.com/uipath/original/4X/9/0/3/903a6597548eeb54905cf78b356a9a2354a3540c.png)

---

<div class="post-metadata">

**Author:** ![Yudhisteer\_Chintaram1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yudhisteer_chintaram1/32/308433_2.png) [@Yudhisteer\_Chintaram1](https://forum.uipath.com/u/Yudhisteer_Chintaram1)\
**Post date:** [January 25, 2022, 12:58pm UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/17 "2022-01-25T12:58:57Z")

</div>

[Extract\_Country.xaml](https://forum.uipath.com/uploads/short-url/wcLZ91FRH4zGCwAO3RVOTDi2OOG.xaml) (7.9 KB)

Can you share yours please?

---

<div class="post-metadata">

**Author:** ![ptrobot](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ptrobot/32/175001_2.png) [@ptrobot](https://forum.uipath.com/u/ptrobot)\
**Post date:** [January 25, 2022, 1:08pm UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/18 "2022-01-25T13:08:32Z")

</div>

Of course. Here’s my workflow:

[InvokePythonTest.xaml](https://forum.uipath.com/uploads/short-url/bUhv3dnDlMZJAae4SgjkvBCRqX5.xaml) (6.6 KB)

On another note, have you tested to add the full path for the output file? I suspect that the script maybe is writing to a directory that you might not have write access to.

```auto
df.to_excel("c:/test/output.xlsx",sheet_name='Country', index = False)

```

---

<div class="post-metadata">

**Author:** ![ptrobot](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ptrobot/32/175001_2.png) [@ptrobot](https://forum.uipath.com/u/ptrobot)\
**Post date:** [January 25, 2022, 1:25pm UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/19 "2022-01-25T13:25:57Z")

</div>

Your workflow works fine on my computer also. The only difference I can see is that you are using another version of Python (3.8 vs 3.9).

![image](https://global.discourse-cdn.com/uipath/original/4X/f/3/6/f361d9b05ee19fa9fa5baddf0d1fc1135c64d18d.png)

![image](https://global.discourse-cdn.com/uipath/original/4X/2/8/b/28befa6a16ed0a466303401ad321a7c6b6ef64ea.png)

![image](https://global.discourse-cdn.com/uipath/original/4X/f/a/c/fac150073c451995a6dec9b4adb335f0b5812c1e.png)

---

<div class="post-metadata">

**Author:** ![mia1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mia1/32/292573_2.png) [@mia1](https://forum.uipath.com/u/mia1)\
**Post date:** [March 31, 2022, 9:28am UTC](https://forum.uipath.com/t/invoke-pythod-method-error/393809/20 "2022-03-31T09:28:39Z")

</div>

Hi,  
did you find the solution for this error ?

[Next page](https://forum.uipath.com/t/invoke-pythod-method-error/393809.md?page=2)
