Search code examples
pythonpython-3.xpackagepython-importrelative-import

ModuleNotFoundError: No module named 'mononphm'


I have followed the instructions here:

https://github.com/SimonGiebenhain/MonoNPHM?tab=readme-ov-file#31-demo

To run the model by:

python scripts/inference/rec.py --model_type nphm --exp_name pretrained_mononphm --ckpt 2500 --seq_name 00898 --no-intrinsics_provided --downsample_factor 0.33

I'm receiving this error:

Traceback (most recent call last):

File "/home/arisa/MonoNPHM/scripts/inference/rec.py", line 7, in

from mononphm.photometric_tracking.tracking import track

ModuleNotFoundError: No module named 'mononphm'

The error happens when importing by from mononphm:

import json, os, yaml
import torch
import numpy as np
import tyro
from typing import Literal

from mononphm.photometric_tracking.tracking import track
from mononphm.photometric_tracking.wrapper import WrapMonoNPHM
from mononphm.models.neural3dmm import nn3dmm
from mononphm.models import setup_training
from mononphm import env_paths
from mononphm.utils.others import EasyDict

I have tried some solutions here: Relative imports - ModuleNotFoundError: No module named x

But none of the solutions I tried have worked so far.

It looks like others are not getting my error, they go beyond and receive other errors: https://github.com/SimonGiebenhain/MonoNPHM/issues/7#issuecomment-2220001296

Can anyone help?


Solution

  • Conda env

    Not using env PIP

    I had already activated the Conda environment by:

    conda activate mononphm
    

    But PIP of the Conda environment was not being used:

     which pip
    /home/arisa/.local/bin/pip
    

    Solution

    Abs path to PIP & Python of Conda env

    Finally, the error was resolved.

    I call the PIP explicitly by using its absolute path to the Conda environment:

    sudo /home/arisa/.conda/envs/mononphm/bin/pip3 install -e .
    

    Then calling the Python by its absolute path to the Conda environment:

    /home/arisa/.conda/envs/mononphm/bin/python3.9 scripts/inference/rec.py --model_type nphm --exp_name pretrained_mononphm --ckpt 2500 --seq_name 00898 --no-intrinsics_provided --downsample_factor 0.33
    

    The error is resolved now. I'm doing the next troubleshooting.