ImportError Import by filename is not supported

0 votes

.

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.
Nov 26, 2020 in Python by anonymous
• 8,880 points
159 views

1 answer to this question.

0 votes

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
answered Nov 26, 2020 by Gitika
• 65,870 points

Related Questions In Python

0 votes
1 answer

How to install biopyhton if import is not recognised as a command by the system?

Hello, For install biopyhton with proper instruction you can ...READ MORE

answered Oct 12, 2020 in Python by Niroj
• 82,560 points
39 views
0 votes
3 answers

Is python version 3.7.2 supported by pycharm jetbrains IDE?

Yes it works fine.. READ MORE

answered Feb 27, 2019 in Python by Pratosh kumar
435 views
0 votes
1 answer
0 votes
1 answer

mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported

Hi@akhtar, According to SQL documentation for python library. you ...READ MORE

answered Jul 15, 2020 in Python by MD
• 95,060 points
5,006 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,833 views
0 votes
0 answers
0 votes
1 answer

Error is '<' not supported between instances of str and int

your dis is obviously not 1.13, it's ...READ MORE

answered Nov 15, 2020 in Python by Gitika
• 65,870 points
1,288 views
+1 vote
7 answers