Python3.8具有一项新功能,您可以将PYTHONPYCACHEPREFIX环境变量设置为dir路径,以便pycache使用单独的并行文件系统树,而不是每个源目录中的默认__pycache__子目录:
我设置了这个环境变量:
export PYTHONPYCACHEPREFIX="$HOME/.cache/pycache/"
它可以直接通过命令行与python3.8协同工作,但不适用于python3.8 WSGI Web应用程序。 您如何通过WSGI Web应用程序使用它? 这是我的WSGI Web应用程序的示例:
# apache.conf Load python3.8 mod_wsgi (installed mod_wsgi by Python3.8 pip)
LoadModule wsgi_module /path/to/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so
# Vhost
ServerName example1.example.com
# The Python-home runs Python3.8 in venv
WSGIDaemonProcess example1 processes=2 threads=15 display-name=%{GROUP} python-home=/home/ubuntu/web-apps/example1/venv
WSGIProcessGroup example1
WSGIScriptAlias / /home/ubuntu/web-apps/example1/web/app.wsgi
Options -Indexes +FollowSymLinks
Require all granted
# example1/web/app.wsgi
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
from web.app import application
# example1/web/app.py
# Will return "Hello. Python version is 3.8.0"
import sys
def application(environ, start_response):
status = '200 OK'
header = [('Content-type', 'text/html; charset=utf-8')]
content = f"Hello. Python version is {sys.version}"
start_response(status, header)
content = content.encode('utf-8')
return [content]