App Engine Python 3开发环境

huangapple go评论68阅读模式
英文:

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 &quot;/usr/lib/google-cloud-sdk/platform/google_appengine/_python_runtime.py&quot;, line 108, in &lt;module&gt;
    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

  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

  2. 如果您使用捆绑的API,那么我认为您不需要Cloud Datastore模拟器。您可以以与Python 2相同的方式运行您的应用程序。要为Python 3启用捆绑的API,请参阅Google文档

英文:
  1. File &quot;/usr/lib/google-cloud-sdk/platform/google_appengine/_python_runtime.py&quot;, 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 used

    Summary: Make sure Python2 is your default Python executable in which case you can simply do dev_appserver.py app.yaml. If Python2 isn't your default Python executable, then you have to use the command python2 dev_appserver.py

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

huangapple
  • 本文由 发表于 2023年2月23日 22:25:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546135.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定