Skip to content

Run Code without Installation

FlameSky edited this page Mar 17, 2022 · 2 revisions

This page is dedicated to solving the problem of attempted relative import errors.

From version 2.0, we packaged the project and uploaded it to PyPI in the hope of making it easier to use. However, this comes at a cost: the imports get trickier when you try to run the codes without installation(like in version 1.0).

In general, to run the codes without installation, you need to import from outside the package. In other words, the python file calling MMSA functions should be located outside of src/MMSA folder.

You can get rid of the codes outside of src folder, which are used to generate python package. Just keep the MMSA folder inside src.

Suppose the folder structure is as follows:

.
├── MMSA                  # folder containing actual code
│   ├── __init__.py
│   ├── __main__.py
│   ├── config.py
│   ├── data_loader.py
│   ├── run.py
│   ├── config
│   ├── models
│   ├── trains
│   └── utils
└── test.py               # python file to call MMSA functions

Then you should import & run like below:

from MMSA import MMSA_run

MMSA_run('lmf', 'mosi', seeds=[1111], gpu_ids=[1])
Clone this wiki locally