ModuleNotFoundError: No module named 'official'
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
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 Yes I forgot to add path. Thanks
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?
If you're using fish shell you'll have to use this instead:
set --export PYTHONPATH path/to/models $PYTHONPATH
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]
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
#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
I hope using the pip package tf-models-official can help set up the python path.
try in ../models/research pip install tf-models-official
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?
In my case I was missing this:
# From within TensorFlow/models/research/
cp object_detection/packages/tf2/setup.py .
python -m pip install .
just use-> pip install tf-models-official it worked for me
Well you can also just copy the official folder from the models folder in to your python package folder, and it will work too