有没有合适的方法让web2py使用Python3而不是Python2?

2024-09-30 22:09:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经在PythonV2中使用web2py好几年了,现在我想切换到Python3运行时,但我不确定正确的方法是什么

我通常使用here提供的安装脚本安装web2py,它在Ubuntu 18.04下运行

djordje@vmi:~$ python --version
Python 2.7.17
djordje@vmi:~$ python3 --version
Python 3.6.9
djordje@vmi:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic

我尝试将默认Python版本设置为3,如本link中所述,使用:

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3 10

它将默认Python设置为v3,但即使在重新启动服务器后,web2py仍然使用Python v2运行

Version
2.18.5-stable+timestamp.2019.04.08.04.22.03
(Running on nginx/1.14.0, Python 2.7.17)

有没有一种推荐的方法可以将web2py设置为在Linux上与Python 3一起运行


Tags: 方法脚本binhereversionubuntuusrupdate
2条回答

通过卸载一个版本的uwsgi pip包,安装另一个,然后重新启动服务,我们能够在web2py服务器上在python 2和python 3之间切换:

pip uninstall uwsgi
pip3 install uwsgi
service uwsgi restart

经过几天的搜索,我似乎发现了一些很容易实现的东西,并且正在我的案例中工作。感谢以下link

我安装了以下软件:

apt install uwsgi-plugin-python3

然后我在/usr/bin下列出了已安装的插件:

ls /usr/bin/uwsgi_python*

有两种:uwsgi_Python3和uwsgi_Python36,因此我使用:

update-alternatives  set uwsgi /usr/bin/uwsgi_python36

重新启动服务器后,它工作正常:

2.18.5-stable+timestamp.2019.04.08.04.22.03
(Running on nginx/1.14.0, Python 3.6.9)

也许有更好的(首选方式),但我不想添加虚拟环境,也不想更改默认的OS Python版本。这样,我就更新了uwsgi运行时

相关问题 更多 >