Models: ModuleNotFoundError: no module named 'adversarial_text'

Created on 11 Jul 2017  路  9Comments  路  Source: tensorflow/models

kikyo@kikyo-ah-ha:/tmp/adversarial_text$ bazel run data:gen_vocab -- --output_dir=$IMDB_DATA_DIR --dataset=imdb --imdb_input_dir=/tmp/aclImdb --lowercase=False
INFO: Found 1 target...
Target //data:gen_vocab up-to-date:
bazel-bin/data/gen_vocab
INFO: Elapsed time: 0.135s, Critical Path: 0.00s

INFO: Running command line: bazel-bin/data/gen_vocab '--output_dir=/tmp/imdb' '--dataset=imdb' '--imdb_input_dir=/tmp/aclImdb' '--lowercase=False'
Traceback (most recent call last):
File "/home/kikyo/.cache/bazel/_bazel_kikyo/8920fee1eb0b89d4a7850da6ea96fe9d/execroot/__main__/bazel-out/local-fastbuild/bin/data/gen_vocab.runfiles/__main__/data/gen_vocab.py", line 25, in
from adversarial_text.data import data_utils
ModuleNotFoundError: No module named 'adversarial_text'

support

Most helpful comment

Firstly, touch a __init__.py file in data filefold, then you can change this line to import data. data_utils as data_utils.

All 9 comments

I'm getting the same error, output given below. My config: Ubuntu 16.04.2 LTS, Tensorflow 1.2, Python 2.7.12, Bazel 0.5.2. Any help would be much appreciated.

bazel run data:gen_vocab -- --output_dir=$IMDB_DATA_DIR --dataset=imdb --imdb_input_dir=/home/dasgupta/adversarial_text/aclImdb --lowercase=False
INFO: Found 1 target...
Target //data:gen_vocab up-to-date:
bazel-bin/data/gen_vocab
INFO: Elapsed time: 0.260s, Critical Path: 0.00s

INFO: Running command line: bazel-bin/data/gen_vocab '--output_dir=/home/pdasgupta/adversarial_text/imdb' '--dataset=imdb' '--imdb_input_dir=/home/dasgupta/adversarial_text/aclImdb' '--lowercase=False'
Traceback (most recent call last):
File "/home/dasgupta/.cache/bazel/_bazel_dasgupta/a6fb310c6e28131929f137e5e79c22a3/execroot/__main__/bazel-out/local-fastbuild/bin/data/gen_vocab.runfiles/__main__/data/gen_vocab.py", line 26, in
from adversarial_text.data import data_utils
ImportError: No module named adversarial_text.data
ERROR: Non-zero return code '1' from command: Process exited with status 1.

Firstly, touch a __init__.py file in data filefold, then you can change this line to import data. data_utils as data_utils.

Thanks @BinWone . That solved it.

I suspect the @ruyiweicas had this problem because adversarial_text/ was copied into /tmp. Unlike most other examples in TensorFlow Models, the build for this one was designed to be a part of the broader repository, which I admit is confusing.

No touch __init__.py or import rewriting is necessary. The way the example was intended to be run is as follows:

wget http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz -O /tmp/imdb.tar.gz
tar -xf /tmp/imdb.tar.gz -C /tmp
git clone https://github.com/tensorflow/models.git tensorflow-models
cd tensorflow-models
bazel run //adversarial_text/data:gen_vocab -- --output_dir=/tmp/imdb --dataset=imdb --imdb_input_dir=/tmp/aclImdb --lowercase=False

I still get this issue.
My solution is:
create __init__.py file in the same directory with BUILD files. Add the lines:

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

I am also encountering this issue - I ran into it just following the instructions in the README for this example. But the proposed solution by @jart also fails for me. I propose that this issue be re-opened. Once I've gotten a working build process I'm happy to submit a PR that updates the README for this example with proper instructions.

Here's the initial issue, which others saw (leaving out the instructions to download/unpack the IMDB dataset into /tmp/, which was already done following the instructions on the adversarial_text example README):

$ cd; git clone https://github.com/tensorflow/models.git && cd models/research/adversarial_text

$ # commands to download the dataset to /tmp

$ bazel run data:gen_vocab -- --output_dir=/tmp/imdb --dataset=imdb --imdb_input_dir=/tmpbazel run data:gen_vocab --     --output_dir=$IMDB_DATA_DIR     --dataset=imdb     --imdb_input_dir=/tmp/aclImdb     --lowercase=False
INFO: Found 1 target...
Target //research/adversarial_text/data:gen_vocab up-to-date:
  bazel-bin/research/adversarial_text/data/gen_vocab
INFO: Elapsed time: 0.136s, Critical Path: 0.00s

INFO: Running command line: bazel-bin/research/adversarial_text/data/gen_vocab '--output_dir=/tmp/imdb' '--dataset=imdb' '--imdb_input_dir=/tmpbazel' run data:gen_vocab -- '--output_dir=' '--dataset=imdb' '--imdb_input_dir=/tmp/aclImdb' '--lowercase=False'
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_charles/2025f70dbc1313449524d44053c40bb9/execroot/__main__/bazel-out/darwin_x86_64-fastbuild/bin/research/adversarial_text/data/gen_vocab.runfiles/__main__/research/adversarial_text/data/gen_vocab.py", line 26, in <module>
    from adversarial_text.data import data_utils
ImportError: No module named adversarial_text.data
ERROR: Non-zero return code '1' from command: Process exited with status 1.

(Note that this is being run in-place where the repo was checked out, the adversarial_text directory is not moved anywhere.) When I try the solution proposed by @jart, running from the base of the repository, I see:

$ cd; git clone https://github.com/tensorflow/models.git tensorflow-models && cd tensorflow-models
Cloning into 'tensorflow-models'...
remote: Counting objects: 7753, done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 7753 (delta 6), reused 10 (delta 4), pack-reused 7736
Receiving objects: 100% (7753/7753), 158.31 MiB | 2.07 MiB/s, done.
Resolving deltas: 100% (4195/4195), done.

$ bazel run //adversarial_text/data:gen_vocab -- --output_dir=/tmp/imdb --dataset=imdb --imdb_input_dir=/tmp/aclImdb --lowercase=False
.............
ERROR: no such package 'adversarial_text/data': BUILD file not found on package path.
INFO: Elapsed time: 0.277s
ERROR: Build failed. Not running target.

I tried updating that last command slightly, to be bazel run //research/adversarial_text/data, and this failed with the same error as it initially did:

$ bazel run //research/adversarial_text/data:gen_vocab -- --output_dir=/tmp/imdb --dataset=imdb --imdb_input_dir=/tmp/aclImdb --lowercase=False
INFO: Found 1 target...
Target //research/adversarial_text/data:gen_vocab up-to-date:
  bazel-bin/research/adversarial_text/data/gen_vocab
INFO: Elapsed time: 7.909s, Critical Path: 0.06s

INFO: Running command line: bazel-bin/research/adversarial_text/data/gen_vocab '--output_dir=/tmp/imdb' '--dataset=imdb' '--imdb_input_dir=/tmp/aclImdb' '--lowercase=False'
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_charles/2025f70dbc1313449524d44053c40bb9/execroot/__main__/bazel-out/darwin_x86_64-fastbuild/bin/research/adversarial_text/data/gen_vocab.runfiles/__main__/research/adversarial_text/data/gen_vocab.py", line 26, in <module>
    from adversarial_text.data import data_utils
ImportError: No module named adversarial_text.data
ERROR: Non-zero return code '1' from command: Process exited with status 1.

Any assistance with this would be great. As I mentioned I'm happy to update the instructions on the README for this example and submit a PR once we get this figured out.

(For completeness, I'll mention that I also tried @BinWone's solution, adding an empty __init__.py file in data/ and updating the import statements, but saw the same ImportError, this time with data.data_utils. @strnam's solution also did not work; I tried pasting the two lines beginning with import pkgutil into an __init__.py in both data/ and in the root adversarial_text/ directory but both failed with the same error.)

Same results as @charlesreid1
In addition to recommended steps, also cleaned out bazel .cache /research/ directory.

I just edited the import lines not to refer 'adversarial_text.data' because they are in same folder.
Not sure this is intended by author but this solved mine.

ex)
#from adversarial_text.data import document_generators
import document_generators

Adversarial_text has been changed to not use bazel.

Was this page helpful?
0 / 5 - 0 ratings