简体   繁体   English

nltk:在构建 docker 时无法下载 package punkt

[英]nltk: Unable to download package punkt while building docker

I am running this behind corportate proxy我在公司代理后面运行它
Used the command: RUN python -m nltk.downloader punkt使用命令: RUN python -m nltk.downloader punkt

/usr/local/lib/python3.8/runpy.py:127: RuntimeWarning: 'nltk.downloader' found in sys.modules after import of package 'nltk', but prior to execution of 'nltk.downloader'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))

[nltk_data] Error loading punkt: <urlopen error [Errno -2] Name or
[nltk_data]     service not known>
Error installing package. Retry? [n/y/e]
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.8/site-packages/nltk/downloader.py", line 2533, in <module>
    rv = downloader.download(
  File "/usr/local/lib/python3.8/site-packages/nltk/downloader.py", line 790, in download
    choice = input().strip()

EOFError: EOF when reading a line

You probably have to pass the proxy configuration into your container(s) during docker build, see .您可能必须在 docker 构建期间将代理配置传递到您的容器中, 请参阅. This only works if nltk evaluates those standard environment variables, though.不过,这仅在 nltk 评估那些标准环境变量时才有效。

docker build \
  --build-arg HTTP_PROXY=http://10.20.30.2:1234 \
  --build-arg FTP_PROXY=http://40.50.60.5:4567 \
  .

I only experienced this error in PyCharm.我只在 PyCharm 中遇到过这个错误。 When I built my container on the command line using docker build. -t relish/my_image当我使用docker build. -t relish/my_image docker build. -t relish/my_image , the error didn't happen and my PyCharm build started working too. docker build. -t relish/my_image ,错误没有发生,我的 PyCharm 构建也开始工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM