0

I have strcture of my program like this : enter image description here

I want to import some functions in the examples/borrow.py file from src/v1/lend/costants/testnetCostants.py file and from src/v1/lend/borrow.py file how can I do this in a proper way ?

I try this structure but it didn't work :

from src.v1.lend.borrow import prepareAddEscrowTransactions, prepareBorrowTransactions, prepareRepayTransaction
from src.v1.lend.costants.testnetCostants import TestnetOracle, TestnetReserveAddress, TestnetTokenPairs
from config import algodClient, sender

I receive this error "ModuleNotFoundError: No module named 'src'"

thanks all for your help

Simospa
  • 23
  • 4

1 Answers1

0

First of all as a friendly advice, for efficient code management, please use a more organized file structure like this:
file structure example
Then create an venv for every practical project and install appropriate reqiurements. Check the notebook.
After all if you use VScode, change the interpreter to your specific env:
right bottom corner of your vscode

After this, you should not see any warning in your VScode for imports if you enter correct path and install packages completely.


Finally for running:

  1. In your terminal, activate the project env (if your packagemanager is conda, use conda activate your_env_name)
  2. Go to your project directory and use export PYTHONPATH=${PWD}
  3. Then use python src/utils/main.py or your own file path.

it would be better to mention that your modular imports have no problem, if your names and structure are correct by the way. Check the link if it is helpful.

  • I made all of this but when I run my program it says "ModuleNotFoundError: No module named 'src'", how can I remove this error ? – Simospa Jul 13 '22 at 11:29
  • I told you in my structure advice! please read it again. when you want to import some module from a higher level in your filesystem structure, you have to address it from the top dir. in your case, `from examples.src.v1.lend.borrow import something` – Hamed Zeinalzadeh Jul 13 '22 at 13:30