I can't get past the import of "inference.py". Here is my error message:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 163, in _run_module_as_main
mod_name, _Error)
File "/usr/lib/python2.7/runpy.py", line 102, in _get_module_details
loader = get_loader(mod_name)
File "/usr/lib/python2.7/pkgutil.py", line 464, in get_loader
return find_loader(fullname)
File "/usr/lib/python2.7/pkgutil.py", line 474, in find_loader
for importer in iter_importers(fullname):
File "/usr/lib/python2.7/pkgutil.py", line 430, in iter_importers
__import__(pkg)
File "nmt.py", line 28, in
from . import inference
ValueError: Attempted relative import in non-package
I get the same issue:
Traceback (most recent call last):
File "C:/Users/nave01314/IdeaProjects/nmt/nmt/nmt.py", line 28, in <module>
from . import inference
ImportError: cannot import name 'inference'
I solved this problem by executing the command in the "gnmt-master" directory, I guess you executing the command in the "gnmt-master/nmt" directory.
I was also in the nmt sub-directory. This is my entire command-line:
(env) dludwig1@AspireMachineLearning:/media/DataHD2/nmt/nmt$ python -m nmt.nmt
--src=vi --tgt=en \ --vocab_prefix=/media/DataHD2/nmt/nmt_data/vocab \ --train_prefix=/media/DataHD2/nmt/nmt_data/train \ --dev_prefix=/media/DataHD2/nmt/nmt_data/tst2012 \ --test_prefix=/media/DataHD2/nmt/nmt_data/tst2013 \ --out_dir=/media/DataHD2/nmt/nmt_model \ --num_train_steps=12000 \ --steps_per_stats=100 \ --num_layers=2 \ --num_units=128 \ --dropout=0.2 \ --metrics=bleuTraceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 163, in _run_module_as_main
mod_name, _Error)
File "/usr/lib/python2.7/runpy.py", line 102, in _get_module_details
loader = get_loader(mod_name)
File "/usr/lib/python2.7/pkgutil.py", line 464, in get_loader
return find_loader(fullname)
File "/usr/lib/python2.7/pkgutil.py", line 474, in find_loader
for importer in iter_importers(fullname):
File "/usr/lib/python2.7/pkgutil.py", line 430, in iter_importers
__import__(pkg)
File "nmt.py", line 28, in
from . import inference
ValueError: Attempted relative import in non-package
Am I using the wrong version of Python?
Fansiawant - you are absolutely right! I moved up one directory and it worked fine.
Thank you, Dana
I'm still having issues with this. I don't have a directory to move up into - when I cloned into Intellij, I ended up with the path ~IdeaProjectsnmt... .
Screenshot of issue, project structure, and run configuration: http://imgur.com/RVNDhf0
nave01314: Your error message was a bit different than mine. I had other errors before too, and one thing that helped was when I did a completely fresh download of the scripts just before I ran the scripts. It seems that the scripts are actively evolving, along with the data, and you need a complete snapshot of the demo to prevent some bugs.
@danaludwig Recloning and rerunning did not fix the issue.
Sounds worth asking others; I don't know how to un-close this thread. Perhaps you could post your bug on a new thread?
I've done so.
nave01314: I think you just need to move up one directory to the first "nmt", then your path maybe like this:
~\IdeaProjects\nmt\
You can execute the command in that path like this:
~\IdeaProjects\nmt$ python -m nmt.nmt ....blabla....
I try by changing directry, but it can't resolve my same error:
python nmt.py \
> --src=vi --tgt=en \
> --vocab_prefix=tmp/nmt_data/vocab \
> --train_prefix=tmp/nmt_data/train \
> --dev_prefix=tmp/nmt_data/tst2012 \
> --test_prefix=tmp/nmt_data/tst2013 \
> --out_dir=/tmp/nmt_model \
> --num_train_steps=12000 \
> --steps_per_stats=100 \
> --num_layers=2 \
> --num_units=128 \
> --dropout=0.2 \
> --metrics=bleu
Again, it gives me error as:
File "nmt.py", line 28, in
from . import inference
ValueError: Attempted relative import in non-package
For IDEA users, I answered in https://github.com/tensorflow/nmt/issues/46
For console users, there is an example of command line in README.md, which says you should'n run the script nmt.py , you should pass the nmt module to python
python -m nmt.nmt
Look at here https://github.com/tensorflow/nmt/issues/313
I've already got to know why it runs with python -m nmt.nmt? The first nmt is the directory and second nmt that actually is nmt.py. So there is a little perplexity to most programmers I think.
So we have to locate the directory here, as the screenshot shown below.
