为Heroku Web应用程序切换python解释器[已关闭]

hsgswve4  于 2022-11-13  发布在  Python
关注(0)|答案(1)|浏览(150)

**已关闭。**此问题为not about programming or software development。目前不接受答案。

此问题似乎与a specific programming problem, a software algorithm, or software tools primarily used by programmers无关。如果您认为此问题与another Stack Exchange site相关,您可以留下评论,说明在何处可以找到此问题的答案。
9天前关闭。
Improve this question

问题对于上下文:

  • 我已经为Heroku部署了一个应用程序
  • 我在VS Code中本地运行Python 3.9.2,而在Heroku机器上运行Python 3.10.8

我目前遇到的问题提到的this线程。
我发现我的问题的解决方案似乎是切换python解释器,并将我的各种包复制到该位置。
但是,在Heroku中几乎没有关于如何执行此操作的文档。
任何帮助都非常感谢:)

我尝试过的方法由于缺少上述方法的文档,我尝试了以下方法...

我发现Heroku部署运行在Python 3.10.8运行时上,而我的本地机器运行的是Python 3.9.2。
然后,我在Github中应用目录的根目录下添加了一个runtime.txt,指定使用3.9.2,但当我尝试重新部署时,构建失败了。
根据Heroku的日志,这让我想到:

-----> Building on the Heroku-22 stack
-----> Using buildpack: heroku/python
-----> Python app detected
-----> Using Python version specified in runtime.txt
 !     Requested runtime 'cat runtime.txt
python-3.9.2' is not available for this stack (heroku-22).
 !     For supported versions, see: https://devcenter.heroku.com/articles/python-support
 !     Push rejected, failed to compile Python app.
 !     Push failed

然后,我从日志中意识到,构建包不是3.9.2版,不受支持。
然后,我在本地机器上下载了python 3.11.0(正如这里提到的,它是受支持的)。
停用当前虚拟环境(使用3.9.2)。
已创建新的虚拟环境。
在本地重新运行应用程序,并检查其是否工作正常。
然后,我将更改添加到git repo中。
然后我试着在Heroku上部署

-----> Building on the Heroku-22 stack
-----> Using buildpack: heroku/python
-----> Python app detected
-----> Using Python version specified in runtime.txt
 !     Requested runtime 'cat runtime.txt
python-3.11.0' is not available for this stack (heroku-22).
 !     For supported versions, see: https://devcenter.heroku.com/articles/python-support
 !     Push rejected, failed to compile Python app.
 !     Push failed

然后导航到support documentation
然后,我尝试并遵循关于“检查构建包版本”的支持指导,因为我的Python版本是支持的,正如文档所示。
我在CLI上运行该命令,检查我使用的是哪个构建包版本。

=== [appnamegoeshere] BuildPack URL
heroku/python

所以,我有了“heroku/python”构建包。
不确定下一步该怎么走?
任何帮助都非常感谢:)

x6492ojm

x6492ojm1#

选择运行时的文档说明:
要指定Python运行时,请将runtime.txt文件添加到应用的根目录,该文件声明要使用的确切版本号:

$ cat runtime.txt
python-3.10.8

其中的cat runtime部分是一个可以在许多系统(Linux,macOS等)上运行的命令,用来打印文件的内容,它不应该包含在文件中。
你的runtime.txt应该只包含相应的python-x.y.z行,目前,在Heroku-22栈上,你可以使用Python 3.9:

python-3.9.15

Python 3.10:

python-3.10.8

或者Python 3.11:

python-3.11.0

您在本地计算机上使用的版本通常只需要匹配主要部分和次要部分:您本地Python 3.9.3应该与Heroku的3.9.15兼容。
请注意,Heroku支持的Python版本列表会随着新补丁的发布而频繁更新。

相关问题