sheffieldnlp/stance-conditional

problem with imports

Closed this issue · 4 comments

Got a fresh copy from github and initialized modules and pythonpath:

echo $PYTHONPATH
/Users/andreasvlachos/Work/git/stance-conditional/twokenize_wrapper:/Users/andreasvlachos/Work/git/stance-conditional/

But when I run:
stancedetection andreasvlachos$ python3 word2vec_training.py

I get:
Traceback (most recent call last):
File "word2vec_training.py", line 4, in
from preprocess import tokenise_tweets, build_dataset, transform_tweet, transform_labels
File "/Users/andreasvlachos/Work/git/stance-conditional/stancedetection/preprocess.py", line 4, in
from twokenize_wrapper.twokenize import tokenize
ImportError: No module named 'twokenize_wrapper.twokenize'; 'twokenize_wrapper' is not a package

Could you check? I was getting past this in the previous commit.

Hi Andreas,

The error message indicates there was a problem with the naming of the twokenizer submodule.

If you import it like this

git submodule add https://github.com/leondz/twokenize.git twokenize_wrapper

it should work. Alternatively, change the import statement in preprocess to

TWOKENIZER-SUBMODULE-NAME.twokenize import tokenize

I think I am doing it the right way, but just in case here is the full command sequence:

(stanceEMNLP2016) Andreass-MBP-3:git andreasvlachos$ git clone https://github.com/sheffieldnlp/stance-conditional.git

(stanceEMNLP2016) Andreass-MBP-3:git andreasvlachos$ cd stance-conditional/

(stanceEMNLP2016) Andreass-MBP-3:stance-conditional andreasvlachos$ git submodule add https://github.com/leondz/twokenize.git twokenize_wrapper

(stanceEMNLP2016) Andreass-MBP-3:stance-conditional andreasvlachos$ cd stancedetection/

(stanceEMNLP2016) Andreass-MBP-3:stancedetection andreasvlachos$ python3 word2vec_training.py
Traceback (most recent call last):
File "word2vec_training.py", line 4, in
from preprocess import tokenise_tweets, build_dataset, transform_tweet, transform_labels
File "/Users/andreasvlachos/Work/git/stance-conditional/stancedetection/preprocess.py", line 4, in
from twokenize_wrapper.twokenize import tokenize
ImportError: No module named 'twokenize_wrapper.twokenize'; 'twokenize_wrapper' is not a package

Is there something wrong in the above?

Checked it out from scratch like you did and was able to reproduce the error. It's not recognised as a package because there's no init file, so you need to manually create one, i.e. create an emtpy
twokenize_wrapper/__init__.py
file

Yes, this fixed it. Added it to the instructions.