How to install libraries python-docx / docx on Google Cloud Shell?

Viewed 743

I work with python-docx and docx in my PC, but when I've cloned the project to Google Cloud, the problems arose. Both docx and python-docx are installed there:

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

Problem with 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  

Update

The installing of those 3-d party libraries into project lib folder has benefited, now these packages in project/lib folder. Yet, now the error in lxml library:

  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

By the way, this was a right way since:

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

1 Answers
Related