Search code examples
pythonimportattributeerror

no attribute error in python while importing other python file


i import another python file in my current python file. when i call function from imported python file it show Attribute Error: module 'abc' has no attribute 'classify'. how to solve this issue?

app.py

import abc
a=abc.classify(upload)

abc.py

def classify(data):
  app.logger.debug('Running classifier')
  upload = data
  image = load_image(upload)
  #load_image() is to process image :
  print('image ready')

please tell me what goes wrong in this. i use python version 3.7.4.


Solution

  • This is due to 'abc' is a python standard library

    https://docs.python.org/3/library/abc.html

    So when you import it with import abc, you are actually importing the standard one, not your own module. So, either you choose another name for it or you do a relative import; if it's in the same path level of your other file you can do import .abc

    But I recommend you to choose another name to avoid further issues