Skip to content
Advertisement

Not able to import python files needed in main.py

I have this file structure which i am not too sure is considered good practice. here is the directory structure

my projects file structure

I am trying to import the content of seed.py and wallet_generation.py into my main.py file. But when I try import the files through a relative path ie (../../bitcoinBackend/seed and ../../bitcoinBackend/wallet_generation) I get errors where the files are not recognized.

Im assuming that my file structure will need some cleaning up, but if ye have any tips on how I should rearrange my file structure or on how to properly import these 2 python files id greatly appreciate it.

EDIT: The error message is just a ModuleNotFoundError

Advertisement

Answer

You can give relative imports a try.

In practice, in main.py, you could import wallet_generation like so:

from ...bitcoinBackend.locales import wallet_generation

Roughly speaking, if you call main.py as part of a package, then:

  • .. will refer to the parent directory of main.py

  • ... will refer to the 2nd parent directory of main.py

  • . would refer to the directory in which main.py is

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement