google-app-enginegoogle-cloud-platformgoogle-cloud-sdkdev-appserver

Google App Engine, dev_appserver.py: WindowsError: [Error 2] The system cannot find the file specified


I'm trying to run the Google App Engine local development server (dev_appserver.py), using the following command:

python3 "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\dev_appserver.py" "C:\Users\myusername\Desktop\test_gae_python3\app.yaml"

However I get the following exception:

# INFO     2023-02-15 23:27:07,500 devappserver2.py:317] Skipping SDK update check.
# INFO     2023-02-15 23:27:07,720 <string>:384] Starting API server at: http://localhost:50618
# INFO     2023-02-15 23:27:07,747 instance_factory.py:155] Detected python version "Python 3.9.13
# " for runtime "python39" at "python3".
# Actual environment location may have moved due to redirects, links or junctions.
#   Requested location: "c:\users\myuser~1\appdata\local\temp\tmp2cocmu\Scripts\python3.exe"
#   Actual location:    "C:\Users\myusername\AppData\Local\Temp\tmp2cocmu\Scripts\python3.exe"
# INFO     2023-02-15 23:27:17,122 instance_factory.py:312] Using pip to install dependency libraries; pip stdout is redirected to c:\users\myuser~1\appdata\local\temp\tmpsvzpsq
# INFO     2023-02-15 23:27:17,154 instance_factory.py:334] Running c:\users\myuser~1\appdata\local\temp\tmp2cocmu\bin\pip install --upgrade pip
# INFO     2023-02-15 23:27:17,155 stub_util.py:360] Applying all pending transactions and saving the datastore
# INFO     2023-02-15 23:27:17,157 stub_util.py:363] Saving search indexes
# Traceback (most recent call last):
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 109, in <module>
#     _run_file(__file__, globals())
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 103, in _run_file
#     _execfile(_PATHS.script_file(script_name), globals_)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 83, in _execfile
#     execfile(fn, scope)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 645, in <module>
#     main()
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 633, in main
#     dev_server.start(options)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 401, in start
#     options.api_host, apiserver.port, wsgi_request_info_)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\dispatcher.py", line 272, in start
#     ssl_port)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\dispatcher.py", line 409, in _create_module
#     ssl_port=ssl_port)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\module.py", line 1356, in __init__
#     super(AutoScalingModule, self).__init__(**kwargs)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\module.py", line 615, in __init__
#     self._module_configuration)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\module.py", line 242, in _create_instance_factory
#     module_configuration=module_configuration)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\instance_factory.py", line 207, in __init__
#     self._SetupVirtualenvFromConfiguration()
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\instance_factory.py", line 233, in _SetupVirtualenvFromConfiguration
#     self._venv_dir, self._OrigRequirementsFile)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\instance_factory.py", line 359, in _SetupVirtualenv
#     self._RunPipInstall(venv_dir, requirements_file_name)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\instance_factory.py", line 335, in _RunPipInstall
#     pip_proc = subprocess.Popen(pip_cmd, stdout=pip_out, env=pip_env)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\bundledpython2\lib\subprocess.py", line 390, in __init__
#     errread, errwrite)
#   File "C:\Users\myusername\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\bundledpython2\lib\subprocess.py", line 640, in _execute_child
#     startupinfo)
# WindowsError: [Error 2] The system cannot find the file specified

C:\Users\myusername\Desktop\test_gae_python3\app.yaml:

runtime: python39
app_engine_apis: true
service: default
entrypoint: python3 -m app

C:\Users\myusername\Desktop\test_gae_python3\app.py:

print('OK')

Of course this is a minimal scenario to reproduce the problem, my actual application is much more complex.

Environment:

I have no other versions of Python installed in the system.

I've tried reverting the SDK back to 367.0.0 and I get the same exact exception.

Google Cloud SDK 366.0.0 raises a different exception which I don't think is relevant but I can paste if useful.

Background: I'm trying to migrate a Python 2 server to version 3, but I got stuck at this stage and can't wrap my head around it.


Solution

  • This isn't supported by Google. According to Google documentation

    The dev_appserver tool does not support development of Python 3 apps on Windows.

    I believe it's because gunicorn doesn't run on Windows. But if you still want to use dev_appserver.py for Python 3 Apps on a Windows machine, you can check out a Patch we created (the patch essentially swaps out Gunicorn for Waitress when running your App on your dev machine)