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,870 points
2,899 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,770 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,840 points
648 views
0 votes
3 answers

Is python version 3.7.2 supported by pycharm jetbrains IDE?

Yes it works fine.. READ MORE

answered Feb 28, 2019 in Python by Pratosh kumar
1,426 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,460 points
31,433 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,466 views
0 votes
1 answer
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,770 points
5,593 views
+1 vote
7 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP