英文:
App Engine Python 3 development environment
问题
我正在尝试将我的App Engine应用从Python 2升级到Python 3。我的应用使用App Engine数据存储(现在是Cloud Datastore)。谷歌的文档并没有清楚地说明如何在本地测试这些内容。我尝试了dev_appserver.py(多年来一直在Python 2上使用),但出现了以下错误:
File "/usr/lib/google-cloud-sdk/platform/google_appengine/_python_runtime.py", line 108, in <module>
assert sys.version_info[0] == 2
AssertionError
我已经安装了Python 3和Python 2。
... 我在Ubuntu上使用Python虚拟环境进行开发。
谢谢
英文:
I'm trying to upgrade my app engine app from python 2 to python 3. My app uses the app engine datastore (now cloud datastore). Google's docs are not at all clear about how to test this stuff locally. I've tried dev_appserver.py (which I've used for years with Python 2) but that's yielding the following error:
File "/usr/lib/google-cloud-sdk/platform/google_appengine/_python_runtime.py", line 108, in <module>
assert sys.version_info[0] == 2
AssertionError
I do have both Python 3 & Python 2 installed.
... I'm using Ubuntu for development in a Python virtual environment
Thank you
答案1
得分: 1
-
上述错误意味着您尝试使用非Python 2可执行文件启动
dev_appserver.py
。无论目标应用程序是用哪种运行时或版本编写的(即使您的应用程序是用Python 3编写的),都需要使用Python2调用dev_appserver.py
。正如文档所述:如果Python 2不是您系统上的默认解释器,请运行
python2 dev_appserver.py
以确保使用Python 2解释器摘要: 确保
Python2
是您的默认Python可执行文件,这样您只需执行dev_appserver.py app.yaml
。如果Python2
不是您的默认Python可执行文件,则必须使用命令python2 dev_appserver.py
。 -
如果您使用捆绑的API,那么我认为您不需要Cloud Datastore模拟器。您可以以与Python 2相同的方式运行您的应用程序。要为Python 3启用捆绑的API,请参阅Google文档。
英文:
-
File "/usr/lib/google-cloud-sdk/platform/google_appengine/_python_runtime.py", line 108, in assert sys.version_info[0] == 2 AssertionError
The above error means you tried to start
dev_appserver.py
with a non-python2 executable.dev_appserver.py
needs to be invoked with Python2 no matter the runtime or version in which your target App is written (i.e. even if your App is written in Python 3). As the documentation says> If Python 2 is not the default interpreter on your system, you need to run
python2 dev_appserver.py
to ensure the Python 2 interpreter is usedSummary: Make sure
Python2
is your default Python executable in which case you can simply dodev_appserver.py app.yaml
. IfPython2
isn't your default Python executable, then you have to use the commandpython2 dev_appserver.py
-
If you use the bundled APIs, then I don't believe you'll need the Cloud Datastore Emulator. You can run your App the same way you were doing it for Python 2. To enable bundled APIs for Python 3, see Google documentation
答案2
得分: 0
dev_appserver.py现在与Python 3兼容。可以直接使用python3运行它,或确保python3是默认的Python解释器。
英文:
The short answer is that dev_appserver.py does now work with Python 3. Either invoke it directly with python3 or make sure that python3 is the default python interpreter.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论