我想在docker中运行nltk服务。但是我总是收到错误消息"' nltk'不是包裹"。你能弄清楚出了什么问题吗?在构建期间一切正常,打印nltk版本。使用docker-compose up nltk
启动容器时,我得到了
$ docker-compose up nltk
Recreating nltk
Attaching to nltk
nltk | Traceback (most recent call last):
nltk | File "/var/www/nltk.py", line 1, in <module>
nltk | from nltk.corpus import brown
nltk | File "/var/www/nltk.py", line 1, in <module>
nltk | from nltk.corpus import brown
nltk | ModuleNotFoundError: No module named 'nltk.corpus'; 'nltk' is not a package
搬运工-compose.yml
nltk:
build: docker/nltk
container_name: nltk
volumes:
- ./volumes/nltk/var/www/nltk.py:/var/www/nltk.py
environment:
HOME: /var/www
Dockerfile
FROM python:3.6
RUN mkdir /var/www
ENV HOME /var/www
WORKDIR /var/www
RUN pip install -U nltk
RUN pip install -U numpy
RUN python -m nltk.downloader -d $HOME/nltk_data all
RUN python -c "import nltk"
RUN python -c "import nltk; print(nltk.__version__)"
EXPOSE 80
CMD [ "python", "/var/www/nltk.py" ]
nltk.py
import nltk
from nltk.corpus import brown
brown.words()
答案 0 :(得分:0)
尝试将(odd? 3)
重命名为其他内容。我猜测(cons 3 '())
和nltk.py
正在尝试从您的import nltk
文件而不是包中导入。它在构建映像时的工作原因是因为您的from nltk.corpus
文件尚不存在,因为它是在运行时从撰写文件中挂载的。
答案 1 :(得分:0)
最终的Dockerfile
FROM python:3.6
ENV NLTK_DATA /usr/share/nltk_data
RUN pip install -U nltk
RUN pip install -U numpy
RUN python -m nltk.downloader -d /usr/share/nltk_data all
EXPOSE 80
WORKDIR /var/www
CMD [ "python", "/var/www/main.py" ]
最终的docker-compose
nltk:
build: docker/nltk
container_name: nltk
volumes:
- ./volumes/nltk/var/www/main.py:/var/www/main.py