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

时间:2018-09-07 14:44:14

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

我在PC上使用 python-docx docx ,但是当我将项目克隆到Google Cloud时,出现了问题。 docx和python-docx均在以下位置安装

#{sessionScope[constants.constantAttributeName].field}

docx.Document 的问题:

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)$

更新

The installing of those 3-d party libraries into project lib文件夹受益,现在这些软件包位于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 文件夹中。但是,现在project/lib库中的错误:

lxml

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

  

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

1 个答案:

答案 0 :(得分:0)

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

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