Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: no module named 'adversarial_text' #1917

Closed
ruyiwei-cas opened this issue Jul 11, 2017 · 9 comments
Closed

ModuleNotFoundError: no module named 'adversarial_text' #1917

ruyiwei-cas opened this issue Jul 11, 2017 · 9 comments

Comments

@ruyiwei-cas
Copy link

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'

@dasguptap
Copy link

dasguptap commented Jul 12, 2017

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.

@BinWone
Copy link

BinWone commented Jul 13, 2017

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

@dasguptap
Copy link

Thanks @BinWone . That solved it.

@jart
Copy link
Contributor

jart commented Jul 13, 2017

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

@jart jart closed this as completed Jul 13, 2017
@strnam
Copy link

strnam commented Sep 27, 2017

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__)

@charlesreid1
Copy link
Contributor

charlesreid1 commented Oct 26, 2017

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.)

@gbolcer
Copy link

gbolcer commented Oct 30, 2017

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

@besarsol
Copy link

besarsol commented Dec 5, 2017

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

@a-dai
Copy link
Collaborator

a-dai commented Feb 22, 2018

Adversarial_text has been changed to not use bazel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants