Models: ImportError: No module named nets, r0.12

Created on 9 Dec 2016  ·  22Comments  ·  Source: tensorflow/models

I am trying to run resnet_v2.py from provided modles but getting error ImportError: No module named nets.
I have done following
First installing slim
cd $HOME/tensorflow git clone https://github.com/tensorflow/models/

To verify that this has worked, execute the following commands; it should run
without raising any errors.

cd $HOME/tensorflow/models/slim python3 -c "from nets import cifarnet; mynet = cifarnet.cifarnet"
I got no error.

But when I run following gives error "ImportError: No module named nets". I have also tried
cd $HOME/tensorflow/models/slim/ python3 -c "from nets import resnet_utils"

Got not error. Also build using bazel build nets output INFO: Found 1 target... Target //slim:nets up-to-date (nothing to build) INFO: Elapsed time: 0.096s, Critical Path: 0.00s

Same thing happen when try to run Inception with error ImportError: No module named inception

I don't know why this is not working.

builinstall

Most helpful comment

@codeloverr Here is your solution tried and tested . Just add slim path to your PYTHONPATH in bashrc file
export PYTHONPATH="$PYTHONPATH:/home/airig/tf-src/tensorflow/models/slim"

And it works!!

All 22 comments

@michaelisard I posted the here because of no response of #6211 . Yet no response, closed both issues. (Y)

I left this one open but haven't had a chance to respond yet.

OK. I hope I get response asap.

I'm not encountering this problem with python 2.7. in ~/src/tf_models/slim on my machine with r0.12 I run python -c "from nets import cifarnet; mynet = cifarnet.cifarnet" and get:

± python  -c "from nets import cifarnet; mynet = cifarnet.cifarnet"
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so.8.0 locally

Though I do encounter the following, I expect it can be fixed with some python path configuration:

~/src/tf_models/slim on master
± python nets/resnet_v2_test.py
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so.8.0 locally
Traceback (most recent call last):
  File "nets/resnet_v2_test.py", line 24, in <module>
    from nets import resnet_utils
ImportError: No module named nets
-> [1]

@adarob Running python -c "from nets import cifarnet; mynet = cifarnet.cifarnet" gives no error if run the command in models > slim folder.
screenshot from 2016-12-13 12-52-41

I don't know the reason why this isn't working.

you solve this problem?, i got the same issue

No, I have found no solution.

@sguada Any updates? With latest version installation, I am still getting the error.

If you understand the relative import and absolut import of python, then you will understand why
""python -c "from nets import cifarnet; mynet = cifarnet.cifarnet""" will reported error @codeloverr

@codeloverr Here is your solution tried and tested . Just add slim path to your PYTHONPATH in bashrc file
export PYTHONPATH="$PYTHONPATH:/home/airig/tf-src/tensorflow/models/slim"

And it works!!

@anuj2rock This solution works for me!

BTW it's not worked on Github.

Hello,

When I try your solution I have : export nis not recognized ...

export PYTHONPATH="$PYTHONPATH:/... is ok for windows ?

Sorry, it might be a stupid question.. I am new in python..

@madekwe You can try manually adding the path to system variables. In Control Panel, look for "Edit the system environment variables", then "Environment Variables..." and add append your desired path to the end of "Path" variable. Hope it helps!

The error is accruing because nets is not a module. It is a folder that contains different modules. Instead of writing from nets import inception_utils simply writeimport inception_utils Similarly for cifarnet, type import cifarnet rather than from nets import cifarnet. This will remove the error no module named nets

Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!

Can someone provide a proper solution for windows?

same issue for mac OS, I am using pip3 PyCharm with Python 3.6.

I had a lot of trouble with this too on Windows even after updating the PYTHONPATH. I found a brute force solution.

For all files where they use "from nets import...", I switched it too "from slim.nets import ..."

This requires going through a couple dozen files and updating, takes about 20 minutes max.

Hopefully this is useful to someone!

@burtonw0814 it works, thx

@burtonw0814 It doesn't work for me: I still have an issue saying:
ModuleNotFoundError: No module named 'slim'

@ljmouline Perhaps you could try specifying even more context:

"from rest.of.path.slim.nets import..."

Was this page helpful?
0 / 5 - 0 ratings