Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Can I call a function from a personal Python Scripit in Power BI

In Python Script in Power BI, I would like to write:

 

from personal_script.py import function

 

Is there a way of doing this?

 

Thank you

  • Anonymous ,

     

    I'm afraid this can't work in power bi. I have created a sample module with simple code in structure like below:

     

    Func/

             __init__.py

            Func1.py

     

    Code in Func.py

    def func():
    	print("Hello World")

    Code in __init__.py

    from Func.Func1 import func
    In visual studio code, codes like below can work:
    import sys
    
    sys.path.append(full_path)
    
    from Func import func
    
    if __name__ == "__main__":
        func()
    But in power bi python script, this can't work:
     
     
    I'm not sure if power bi will always ignore custom path, if you still confuse on this issue, you may submit an issue here.
     

    Community Support Team _ Jimmy Tao

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • v-yuta-msft's avatar
    v-yuta-msft
    Community Support

    Anonymous ,

     

    I'm afraid this can't work in power bi. I have created a sample module with simple code in structure like below:

     

    Func/

             __init__.py

            Func1.py

     

    Code in Func.py

    def func():
    	print("Hello World")

    Code in __init__.py

    from Func.Func1 import func
    In visual studio code, codes like below can work:
    import sys
    
    sys.path.append(full_path)
    
    from Func import func
    
    if __name__ == "__main__":
        func()
    But in power bi python script, this can't work:
     
     
    I'm not sure if power bi will always ignore custom path, if you still confuse on this issue, you may submit an issue here.
     

    Community Support Team _ Jimmy Tao

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you very much for your answer :) it will be nice to have this feature in the future.