2

I am trying to implement the code in https://github.com/kexinyi/ns-vqa.

However, when I try the command, python tools/preprocess_questions.py \ ... in the section of "Getting started". I see a message No module named 'utils.programs'.

Then I install utils and which makes import utils work, but import utils.programs does not work.

Does anyone have any idea to solve it?

import os
import argparse
import json

import h5py
import numpy as np

import utils.programs as program_utils # this one cannot be imported
import utils.preprocess as preprocess_utils
import utils.utils as utils 
David Medinets
  • 5,160
  • 3
  • 29
  • 42
neko kao
  • 35
  • 5
  • Not a `machine-learning` or `computer-vision` question, kindly do not spam irrelevant tags (removed). – desertnaut Aug 16 '20 at 18:09
  • Is there an `__init__.py` in the folder? – Nathan Aug 16 '20 at 18:10
  • https://stackoverflow.com/questions/338768/python-error-importerror-no-module-named – barker Aug 16 '20 at 18:12
  • I don't know why you installed `utils` package because the mention code is not importing that, but it's importing `utils` folder's modules, check `reason` folder and there you're gonna find it. Probably there's a conflict because both of them have the same named, try to desinstall the package and try to run it again. – Brad Figueroa Aug 16 '20 at 18:29

1 Answers1

0

Solution:

Add the below lines at the beginning of preprocess_questions.py file.

import sys
sys.path.insert(0, "..")

This should solve your problem.

Explanation:

It is failing because preprocess_questions.py don't know about the path of utils.programs to import. With the above lines added to the path using .., the required file will be imported.

For more on this refer how importing works in python.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Mithilesh_Kunal
  • 873
  • 7
  • 12