3

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

Pawel Czuczwara
  • 1,442
  • 9
  • 20
Igor Savinkin
  • 5,669
  • 8
  • 37
  • 69
  • [this](https://stackoverflow.com/questions/17688959/importerror-no-module-named-lxml-etree) might help for GAE – Igor Savinkin Sep 07 '18 at 15:26
  • Which app engine environment are you using? – Dustin Ingram Sep 07 '18 at 15:58
  • @Dustin, explain please about *App Engine Enviroment*. – Igor Savinkin Sep 07 '18 at 18:36
  • 1
    He means the flexible environment or standard environment? If you're using the local development server that means its the standard environment as that isn't part of the flexible environment so hopefully you're not mixing instructions from the two different environments. Can you update your question with what your `app.yaml` config file looks like? – BrettJ Sep 08 '18 at 19:01
  • @BrettJ, seems I use google cloud server, not `local development server`. How can I check to be sure which one I use? (see `app.yaml` in my answer) – Igor Savinkin Sep 10 '18 at 08:22

1 Answers1

0

Using Google Cloud Shell is only possible to install persistent data in the $HOME directory. Reaching inactive time limit of 60 minutes, VM Instance will be terminated. Accessing it afterwards, it will be provisioned from the image on the new VM Instance.

However, Google Cloud Shell has 5GB persistent dis storage located in $HOME directory, that does not expire, but may be recycled. User receives email prior recycle process.

Pawel Czuczwara
  • 1,442
  • 9
  • 20