确保以下设置正确。
sudo su
如果您不是root用户
python --version
# run only if the result saying the version is not python 3
rm -rf /usr/bin/python
# create a symlink
ln -s /usr/bin/python3 /usr/bin/python
# test
python --version
apt-get update
apt-get install python3-pip
# disable multi-threading processes
a2dismod mpm_event
# give apache explicit permission to run python scripts
a2enmod mpm_prefork cpi
<Directory your-absolute-site-directory-of-which-index.py-can-be-found>
Options +ExecCGI
DirectoryIndex index.py
Require all granted
# Allow local .htaccess to override Apache configuration settings
AllowOverride all
</Directory>
AddHandler cgi-script .py
service apache2 restart
Options +ExecCGI
AddHandler cgi-script .py
DirectoryIndex index.py
如需更详细的解释,您可以前往
here
.