models icon indicating copy to clipboard operation
models copied to clipboard

ModuleNotFoundError: No module named 'official'

Open Eshan-Agarwal opened this issue 6 years ago • 13 comments

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 (64 bit)
  • Mobile device (e.g., Pixel 4, Samsung Galaxy 10) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary):
  • TensorFlow version (use command below): 2.1.0
  • Python version: 3.7
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version: 10.1
  • GPU model and memory: GTX 1050ti and 4 GB

I am running below script mentioned here and it gives me ModuleNotFoundError: No module named 'official'.

python mnist_main.py
--model_dir=$MODEL_DIR
--data_dir=$DATA_DIR
--train_epochs=10
--distribution_strategy=one_device
--num_gpus=$NUM_GPUS
--download

Eshan-Agarwal avatar Mar 13 '20 15:03 Eshan-Agarwal

If you have cloned the repo, the first step is to add export PYTHONPATH=$PYTHONPATH:/path/to/models /path/to/models means the path the "models" folder. Then it can recognize the sub-folder official.

saberkun avatar Mar 14 '20 03:03 saberkun

@saberkun Yes I forgot to add path. Thanks

Eshan-Agarwal avatar Mar 14 '20 04:03 Eshan-Agarwal

I cloned the repo, added the path, and finished installing the dependencies. There was no problem with this. However, when I try to run mnist codes, I also gets the same errors.

I had added

export PYTHONPATH=$PYTHONPATH:/path/to/models

but still has the same problem as @Eshan-Agarwal.

I am trying to run

python3 mnist_main.py \
  --model_dir=$MODEL_DIR \
  --data_dir=$DATA_DIR \
  --train_epochs=10 \
  --distribution_strategy=one_device \
  --num_gpus=$NUM_GPUS \
  --download

but gets the same error message

ModuleNotFoundError: No module named 'official'

Here is the full error message in case:

2020-04-17 19:40:19.475339: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory
2020-04-17 19:40:19.475565: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory
2020-04-17 19:40:19.475644: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
Traceback (most recent call last):
  File "mnist_main.py", line 28, in <module>
    from official.utils.flags import core as flags_core
ModuleNotFoundError: No module named 'official'

does this below command line should be typed in a specific directory such as the top 'models' folder?

export PYTHONPATH=$PYTHONPATH:/path/to/models

Or is it another problem?

yeeunsong avatar Apr 17 '20 10:04 yeeunsong

If you're using fish shell you'll have to use this instead: set --export PYTHONPATH path/to/models $PYTHONPATH

lustered avatar Jul 10 '20 03:07 lustered

For the same issue on Colab: I had to add the following after cloning the models

!git clone https://github.com/tensorflow/models.git

import os os.environ['PYTHONPATH'] += ":/content/models"

import sys sys.path.append("/content/models")...

Thanks to [https://stackoverflow.com/questions/50121477/tensorflow-no-module-named-official]

PavanproJack avatar Jul 21 '20 15:07 PavanproJack

https://github.com/tensorflow/models/issues/8291#issuecomment-661930520

For the same issue on Colab: I had to add the following after cloning the models

!git clone https://github.com/tensorflow/models.git

import os os.environ['PYTHONPATH'] += ":/content/models"

import sys sys.path.append("/content/models")...

Thanks to [https://stackoverflow.com/questions/50121477/tensorflow-no-module-named-official]

thy it fixt it thy

ekesdf avatar Jul 27 '20 19:07 ekesdf

#do the following in colab it will work !apt-get install protobuf-compiler python-pil python-lxml python-tk !pip install Cython tf_slim !git clone https://github.com/tensorflow/models.git %cd /content/models/research !protoc object_detection/protos/*.proto --python_out=. %set_env PYTHONPATH=/content/models/research:/content/models/research/slim import os os.environ['PYTHONPATH'] += ":/content/models" import sys sys.path.append("/content/models") !python object_detection/builders/model_builder_test.py

amanu1698 avatar Aug 01 '20 11:08 amanu1698

I hope using the pip package tf-models-official can help set up the python path.

saberkun avatar Aug 02 '20 04:08 saberkun

try in ../models/research pip install tf-models-official

ttaahhaa avatar Aug 20 '20 08:08 ttaahhaa

try in ../models/research pip install tf-models-official

Dude i'm getting error model_builder.py. How to set pythonpath to models? i mean from command prompt or environment variables?

nithinreddyy avatar Aug 23 '20 12:08 nithinreddyy

In my case I was missing this:

# From within TensorFlow/models/research/ 
cp object_detection/packages/tf2/setup.py .
python -m pip install .

felipebutcher avatar Apr 08 '21 00:04 felipebutcher

just use-> pip install tf-models-official it worked for me

tzelalouzeir avatar Jun 05 '21 13:06 tzelalouzeir

Well you can also just copy the official folder from the models folder in to your python package folder, and it will work too

ekesdf avatar Jun 09 '21 18:06 ekesdf