I'm trying to import a python file to my application which is written in python.
I have the following code:
import os
from os.path import basename
class specificClass:
def dothing(self,path):
runcommand = __import__("/root/"+ os.path.splitext(os.path.basename(path))[0]+ "/" + os.path.splitext(os.path.basename(path))[0] +"/sa/update.py")
runcommand.main()
When I run it, it gives me the following error:
ImportError: Import by filename is not supported.
Instead of doing a import like __import__
you can say
import sys
sys.path.append(path) # this is where your python file exists
import update
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With