我知道如何执行export
python 路径,但我的问题有点不同。我有 python 3.5,并使用 pip3 安装了 nltk。当我尝试时import nltk.tokenize
,它工作正常:
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk.tokenize
>>>
但是当我运行包含的文件时import nltk.tokenize
,我得到了ImportError: no module named nltk.tokenize
。我知道我必须附加路径,例如sys.path.append('path/to/nltk_data/')
或'export NLTK_DATA='/home/user/nltk_data'
但两者都不起作用。如何在 Ubuntu 16.04 中修复此问题!
编辑
nltk 的路径:/home/ananya/nltk_data
我的项目的路径:/home/ananya/desktop/tenflow/model/research/im2txt/
我正在尝试构建 Tensorflow图片说明如本链接所示
我正在运行的命令是:
bazel-bin/im2txt/download_and_preprocess_mscoco "${MSCOCO_DIR}"
该命令用于下载图像、解压图像,然后运行import nltk.tokenizer
开头包含以下内容的 Python 脚本这导致了这个错误:
Saving to: ‘captions_train-val2014.zip’
captions_train-val2014.zip 100%[======================================================>] 18.76M 4.92MB/s in 4.1s
2018-07-15 18:44:44 (4.59 MB/s) - ‘captions_train-val2014.zip’ saved [19673183/19673183]
Unzipping captions_train-val2014.zip
Traceback (most recent call last):
File "/home/ananya/Desktop/first/models/research/im2txt/bazel-bin/im2txt/download_and_preprocess_mscoco.runfiles/im2txt/im2txt/data/build_mscoco_data.py", line 98, in <module>
import nltk.tokenize
ImportError: No module named nltk.tokenize
我只有 python 2.7 和 3.5,没有 3.6
注释后的python脚本的开头:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from collections import Counter
from collections import namedtuple
from datetime import datetime
import json
import os.path
import random
import sys
import threading
import nltk.tokenize
import numpy as np
from six.moves import xrange
import tensorflow as tf
tf.flags.DEFINE_string("train_image_dir", "/tmp/train2014/",
"Training image directory.")
tf.flags.DEFINE_string("val_image_dir", "/tmp/val2014",
"Validation image directory.")