2017-04-02 4 views
0

Ich möchte einen Nltk-Dienst in Docker ausführen. Allerdings bekomme ich immer die Fehlermeldung "'nltk' ist kein Paket". Können Sie herausfinden, was falsch läuft? Während des Builds funktioniert alles einwandfrei, die Nltk-Version wird gedruckt. Wenn mit docker-compose up nltk den Container starten bekomme ichNLTK funktioniert nicht in Docker

$ Docker-komponieren bis 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 

Docker-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() 

Antwort

0

Versuchen sonst nltk.py etwas umbenennen. Ich schätze, die import nltk und from nltk.corpus versucht, von Ihrer nltk.py Datei anstelle des Pakets zu importieren. Der Grund, warum es beim Erstellen des Images funktioniert, ist, dass Ihre nltk.py Datei noch nicht existiert, da sie zur Laufzeit aus der Compose-Datei geladen wird.

+0

Großen. Ich denke, das hat den Trick gemacht. Vielen Dank! Ich werde die endgültige Version veröffentlichen – Sebastian

0

final 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" ] 

final Docker-komponieren

nltk: 
    build: docker/nltk 
    container_name: nltk 
    volumes: 
     - ./volumes/nltk/var/www/main.py:/var/www/main.py