0

I need to import 2 variables from a main file into an additional one. These variables are used in the numba function of the additional file, which is called in the main.

main file:

import file2

SIGMA = 10
MEAN = 0

q = file2.compute(img)

additional file:

import numba as nb
from main import SIGMA, MEAN

@nb.njit('uint8[:,:,::1](uint8[:,:,::1])', parallel=True)
def compute(image):
    return = function(MEAN,SIGMA)

But the code threw:

File "D:\", line 5, in <module>
    from main import SIGMA, MEAN
File "D:\", line 18, in <module>
    q = file2.compute(img)
AttributeError: partially initialized module 'file2' has no attribute 'compute' (most likely due to a circular import)
davidsbro
  • 2,761
  • 4
  • 23
  • 33
SergioX13
  • 23
  • 4
  • Does this answer your question? [Circular (or cyclic) imports in Python](https://stackoverflow.com/questions/744373/circular-or-cyclic-imports-in-python) – LeopardShark Jan 16 '22 at 14:28
  • The issue is that you are import things from main in file2 and stuff from file2 into main. That is a circular import. You can resolve that by for example moving the constants to another file an import them from there both in main and in file2 – Simon Hawe Jan 16 '22 at 14:29

1 Answers1

0

Pass in parameters rather than importing constants

import numba as nb

@nb.njit('uint8[:,:,::1](uint8[:,:,::1])', parallel=True)
def compute(image, mean, sigma):
    return function(mean,sigma)  # the equal sign seems like a typo 

Then, you can use

import file2

SIGMA = 10
MEAN = 0

q = file2.compute(img, SIGMA, MEAN) 
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245