gpt4 book ai didi

python - 无法在docker中安装nltk

转载 作者:行者123 更新时间:2023-12-02 20:10:24 26 4
gpt4 key购买 nike

我正在尝试在docker上安装nltk软件包,下面是我的docker文件

FROM python:3-onbuild

# COPY startup script into known file location in container
COPY start.sh /start.sh

RUN python -m libs.py

# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000

# CMD specifcies the command to execute to start the server running.
CMD ["/start.sh"]

# done!

libs.py 包含nltk软件包,在require.txt中 nltk == 3.2.5安装了
import nltk
nltk.data.path('libs/')
nltk.download('wordnet')
nltk.download('pros_cons')
nltk.download('snowball_data')
nltk.download('averaged_perceptron_tagger')
nltk.download('averaged_perceptron_tagger_ru')
nltk.download('punkt')
nltk.download('universal_tagset')
nltk.download('maxent_treebank_pos_tagger')
nltk.download('hmm_treebank_pos_tagger')
nltk.download('reuters')
nltk.download('treebank')
nltk.download('vader_lexicon')
nltk.download('porter_test')
nltk.download('rslp')

但是它却给了我关于docker image的错误:
 File "/usr/src/app/training/views.py", line 9, in <module>
from src import main_file as main
File "/usr/src/app/src/main_file.py", line 10, in <module>
from src import aspects_from_correct_data as asp
File "/usr/src/app/src/aspects_from_correct_data.py", line 4, in <module>
from nltk.tag import pos_tag
File "/usr/src/app/nltk.py", line 2, in <module>
nltk.download('wordnet')
AttributeError: module 'nltk' has no attribute 'download'

最佳答案

我正在将Anaconda与nltk==3.2.4一起使用,但未运行Docker。

当我注释掉第二行(libs.py)时,您的nltk.data.path('libs/')脚本对我有用。对于 data Module docsnltk.data.path是一个列表,而不是一个函数。

关于python - 无法在docker中安装nltk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47015589/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com