Reputation: 361
I am trying to use the nets from the official mnist directory of tensorflows model repository. On my windows system I receive this error:
C:\Users\ry\Desktop\NNTesting\models\official\mnist>mnist_test.py
Traceback (most recent call last):
File "C:\Users\ry\Desktop\NNTesting\models\official\mnist\mnist_test.py",line 24, in <module>
from official.mnist import mnist
ModuleNotFoundError: No module named 'official'
I have followed their official directions and set my python path using
set PYTHONPATH="PYTHONPATH:"%cd%"
and can confirm that
PYTHONPATH="$PYTHONPATH:C:\Users\ry\Desktop\NNTesting\models"
and I have also installed the dependencies successfully. Does anyone have experience using these models on a windows system and can help me with this pathing issue? I'm not sure what I have done incorrectly here.
Thanks
Upvotes: 19
Views: 44252
Reputation: 1
I had the same error on windows , after taking the following steps I was able to get rid of this error.
Upvotes: 0
Reputation: 419
For someone struggling in mac os (M1 or any other) set
os.environ['PYTHONPATH'] = 'PYTHONPATH:relative/path/to/Tensorflow/models'
from jupyter notebook as somehow it is not taking it from shell variable so setting it up manually worked also installing
pip install tf-models-official
did not worked for me though it says that dependency is already satisfied.
Upvotes: 0
Reputation: 1
jupyter. Clone from official git and manually appended the path to sys.
!git clone https://github.com/tensorflow/models.git
import sys
sys.path.append("C:/Windows/System32/models")
sys.path
Upvotes: 0
Reputation: 501
add the model directory to PYTHONPATH.
import os
os.environ['PYTHONPATH'] += ':/content/models/research/:/content/models/research/slim/'
Upvotes: 0
Reputation: 293
For Google Colab I needed to add the the model dir also to the Systems path:
!git clone https://github.com/tensorflow/models.git
import os
os.environ['PYTHONPATH'] += ":/content/models"
import sys
sys.path.append("/content/models")
Upvotes: 6
Reputation: 31
I had exactly the same question as you did, and the following solution solved this problem.
There is an error in the tensorflow/models/official README.md
https://github.com/tensorflow/models/tree/master/official
Wrong
export PYTHONPATH="$PYTHONPATH:/path/to/models"
Correct
export PYTHONPATH=$PYTHONPATH:/path/to/models
Upvotes: 3
Reputation: 1
I was setting up to run the NMT model and ran into the same problem. It took me bit to figure out exactly which folder should be added to PYTHONPATH.
I tried several folders inside my example's directory with no luck. I finally understood what that import was trying to tell me... "from official.transformer.utils import tokenizer" means "add the parent of directory 'official' to PYTHONPATH".
For me, this was just the top-level 'models-master' directory that I obtained from GitHub. Once I added /path/to/models-master, I was past this obstacle.
Upvotes: 0
Reputation: 1
I had the same problem. Did you use windows 10? Make sure you run the command prompt as "administrator". I used it in VS code at first, no warning, and didn't work. But it worked when I run a separate prompt window as "administrator".
set PYTHONPATH=path\to\models
then run the model.
Upvotes: 0
Reputation: 1100
The Official Models are made available as a Python module. To run the models and associated scripts, add the top-level /models folder to the Python path with the command: export PYTHONPATH="$PYTHONPATH:/path/to/models"
FROM README
Upvotes: 1
Reputation: 361
if anyone has this problem make sure that the python path variable doesn't have quotations in it. For some reason, the readme has quotations around it.
Here is the correct way to set it
PYTHONPATH=path\to\models
Upvotes: 5