gpt4 book ai didi

python - 如何在 Google Cloud Shell 上安装库 python-docx/docx?

转载 作者:行者123 更新时间:2023-11-28 19:01:25 25 4
gpt4 key购买 nike

我在 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

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

You can install additional software packages on the Coogle Cloud Shell virtual machine instance but the installation will not persist after the instance terminates unless you install the software in your $HOME directory (source).

最佳答案

使用 Google Cloud Shell 只能用于 install persistent data in the $HOME directory .达到 60 分钟的非事件时间限制,VM 实例将被终止。之后访问它,它将从新 VM 实例上的镜像进行配置。

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

关于python - 如何在 Google Cloud Shell 上安装库 python-docx/docx?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52224900/

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