【问题标题】:How to install libraries python-docx / docx on Google Cloud Shell?如何在 Google Cloud Shell 上安装库 python-docx / docx?
【发布时间】:2019-02-12 22:43:18
【问题描述】:

我在我的 PC 上使用 python-docxdocx,但是当我将项目克隆到 Google Cloud 时,问题就出现了。 docx 和 python-docx 都安装在那里:

igorsavinkin555@cloudshell:~/corrections-msword (coral-heuristic-5610)$ pip install docx --user
Requirement already satisfied: docx in /home/igorsavinkin555/.local/lib/python2.7/site-packages (0.2.4)
Requirement already satisfied: lxml in /home/igorsavinkin555/.local/lib/python2.7/site-packages (from docx) (4.2.4)
Requirement already satisfied: Pillow>=2.0 in /home/igorsavinkin555/.local/lib/python2.7/site-packages (from docx) (5.2.0)
igorsavinkin555@cloudshell:~/corrections-msword (coral-heuristic-215610)$ pip install python-docx --user
Requirement already satisfied: python-docx in /home/igorsavinkin555/.local/lib/python2.7/site-packages (0.8.7)
Requirement already satisfied: lxml>=2.3.2 in /home/igorsavinkin555/.local/lib/python2.7/site-packages (from python-docx) (4.2.4)
igorsavinkin555@cloudshell:~/corrections-msword (coral-heuristic-215610)$

docx.Document 的问题:

igorsavinkin555@cloudshell:~/corrections-msword (coral-heuristic-215610)$ dev_appserver.py $PWD
...
INFO     2018-09-07 14:31:48,503 api_server.py:275] Starting API server at: http://0.0.0.0:41739
INFO     2018-09-07 14:31:48,518 dispatcher.py:270] Starting module "default" running at: http://0.0.0.0:8080
INFO     2018-09-07 14:31:48,519 admin_server.py:152] Starting admin server at: http://0.0.0.0:8000
INFO     2018-09-07 14:31:50,533 instance.py:294] Instance PID: 727
ERROR    2018-09-07 14:32:00,844 wsgi.py:263]
Traceback (most recent call last):
  File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/home/igorsavinkin555/corrections-msword/main.py", line 2, in <module>
    from docx.document import Document
ImportError: No module named docx.document  

更新

The installing of those 3-d party libraries into project lib 文件夹已经受益,现在这些包在project/lib 文件夹中。然而,现在lxml 库中的错误:

  File "/home/igorsavinkin555/corrections-msword/main.py", line 2, in <module>
    from docx.document import Document
  File "/home/igorsavinkin555/corrections-msword/lib/docx/__init__.py", line 3, in <module>
    from docx.api import Document  # noqa
  File "/home/igorsavinkin555/corrections-msword/lib/docx/api.py", line 14, in <module>
    from docx.package import Package
  File "/home/igorsavinkin555/corrections-msword/lib/docx/package.py", line 11, in <module>
    from docx.opc.package import OpcPackage
  File "/home/igorsavinkin555/corrections-msword/lib/docx/opc/package.py", line 12, in <module>
    from .part import PartFactory
  File "/home/igorsavinkin555/corrections-msword/lib/docx/opc/part.py", line 12, in <module>
    from .oxml import serialize_part_xml
  File "/home/igorsavinkin555/corrections-msword/lib/docx/opc/oxml.py", line 12, in <module>
    from lxml import etree
  File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/sandbox.py
", line 1095, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named lxml.etree

顺便说一句,这是正确的方法,因为:

您可以在 Coogle Cloud Shell 虚拟机实例上安装其他软件包,但在实例终止后安装将不会持续,除非您将软件安装在 $HOME 目录中 (source)。

【问题讨论】:

  • this 可能对 GAE 有所帮助
  • 您使用的是哪个应用引擎环境?
  • @Dustin,请解释一下 App Engine 环境
  • 他是指柔性环境还是标准环境?如果您使用的是本地开发服务器,这意味着它是标准环境,因为它不是灵活环境的一部分,所以希望您不会混合来自两个不同环境的指令。你能用app.yaml 配置文件的样子更新你的问题吗?
  • @BrettJ,看来我使用的是谷歌云服务器,而不是local development server。我如何检查以确定我使用的是哪一个? (请参阅我的回答中的app.yaml

标签: python google-app-engine google-cloud-platform docx python-docx


【解决方案1】:

只有install persistent data in the $HOME directory 可以使用 Google Cloud Shell。达到 60 分钟的非活动时间限制,VM Instance 将被终止。之后访问它,它将从新 VM 实例上的映像进行配置。

但是,Google Cloud Shell 有 5GB persistent dis storage located in $HOME directory,它不会过期,但可能会被回收。用户在回收过程之前收到电子邮件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-25
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多