Error importing built-in module “_subprocess” using Google Cloud Platform's Local Development Server

回眸只為那壹抹淺笑 提交于 2020-01-13 16:27:05

问题


Does anyone know how I can fix the following error? Error Message: "Import Error

C:\Users\MicroSilicon\Desktop\hello_world>python2 "C:\Users\MicroSilicon\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\dev_appserver.py" app.yaml
INFO     2019-12-16 09:23:23,341 devappserver2.py:285] Skipping SDK update check.
INFO     2019-12-16 09:23:23,506 api_server.py:282] Starting API server at: http://localhost:60054
INFO     2019-12-16 09:23:23,509 dispatcher.py:263] Starting module "default" running at: http://localhost:8080
INFO     2019-12-16 09:23:23,512 admin_server.py:150] Starting admin server at: http://localhost:8000
INFO     2019-12-16 09:23:25,522 instance.py:294] Instance PID: 7284
INFO     2019-12-16 09:23:37,250 module.py:434] [default] Detected file changes:
  main.pyc
WARNING  2019-12-16 15:23:37,354 sandbox.py:1104] The module msvcrt is whitelisted for local dev only. If your application relies on msvcrt, it is likely that it will not function properly in production.
ERROR    2019-12-16 15:23:37,355 wsgi.py:269]
Traceback (most recent call last):
  File "C:\Users\MicroSilicon\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "C:\Users\MicroSilicon\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 311, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "C:\Users\MicroSilicon\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "C:\Users\MicroSilicon\Desktop\hello_world\main.py", line 16, in <module>
    import subprocess
  File "C:\Users\MicroSilicon\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\runtime\sandbox.py", line 1043, in load_module
    return self.import_stub_module(fullname)
  File "C:\Users\MicroSilicon\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\runtime\sandbox.py", line 1049, in import_stub_module
    __import__(fullname, {}, {})
  File "C:\Users\MicroSilicon\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\dist27\subprocess.py", line 8, in <module>
    from python_std_lib import subprocess
  File "C:\Users\MicroSilicon\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\dist27\python_std_lib\subprocess.py", line 417, in <module>
    import _subprocess
  File "C:\Users\MicroSilicon\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\runtime\sandbox.py", line 1113, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named _subprocess

I have installed the Google Cloud SDK for Windows and checked the box to get the bundled python installation (version 2.7.13) with it. Python Installation Check

Basically followed the instructions in the link below to get the Hello World application working in a local environment (up to step "Make a change"). https://cloud.google.com/appengine/docs/standard/python/quickstart

Now, the problem occurred when I added the statement import subprocess to the main.py file.

Note the exact problem is with line import _subprocess in module "subprocess.py". This is strange to me because if I try to run any basic python script (not using dev_appserver.py app.yaml to deploy the Google Cloud Environment) or if I just use the python interpreter directly from the console (Windows Command Prompt) I get no errors when trying toimport subprocess nor if I try to import _subprocess directly. Import Statement from Console Python.

Here is the Hello World code (with added subprocess import):

# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import webapp2
import subprocess

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, World!')



app = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)

Finally, my acquaintance had installed the same software earlier and gets no such error when running any application that uses this import statement.

Note: I am working on a Windows 10 machine.


回答1:


[Update]

I was not able to resolve this issue in my installed version of Google Cloud SDK.

However, installing an older version (specifically version 220.0.0 with bundled python) resolved the import subprocess error. For my purposes this is acceptable.

Here are the details of my working installation:

C:\Users\MicroSilicon>gcloud version
Google Cloud SDK 220.0.0
app-engine-python 1.9.77
app-engine-python-extras 1.9.74
bq 2.0.34
cloud-datastore-emulator 2.0.2
core 2018.10.08
gsutil 4.34



回答2:


I was thinking that as far as we can tell, it could be something wrong with your installation, it could be either your SDK installation and your Python installation, could you reinstall them and check again?

Is just that I tried this with no issues and as you specified someone else did the same and had no issues, maybe the problem is within the installation of either of those products on your pc.



来源:https://stackoverflow.com/questions/59311533/error-importing-built-in-module-subprocess-using-google-cloud-platforms-loca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!