windows10环境下安装django与apache记录
环境
- django3.2
- mod_wsgi
- python3.7
- windows10
- apache2.4
- mysql8.0
下载并安装apache
根据操作系统选择版本,下载链接:apache
浏览器测试是否安装成功
安装mysql
常规安装即可
安装python
根据操作系统选择版本安装,应安装给所有用户
安装在一台不联网机器上,故选择离线安装依赖库
导出依赖
pip freeze > requirements.txt
pip download -r requirements.txt -d ./pip_packages
安装依赖
pip install --no-index --find-links=d:\packages -r requirements.txt
下载并安装mod_wsgi
注意对应python版本,链接mod_wsgi
安装:pip3 install "mod_wsgi-4.5.24+ap24vc14-cp36-cp36m-win_amd64.whl"
输入:mod_wsgi-express module-config
出现提示,复制保留:
LoadFile "D:/python/python37.dll"
LoadModule wsgi_module "f:/pythonproject/file-manage/venv/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "f:/pythonproject/file-manage/venv"
修改httpd.conf
追加
LoadFile "D:/python/python37.dll"
LoadModule wsgi_module "f:/pythonproject/file-manage/venv/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIScriptAlias / f:/pythonproject/file-manage/mysite/mysite/wsgi.py
WSGIPythonHome "f:/pythonproject/file-manage/venv"
WSGIPythonPath "f:/pythonproject/file-manage/mysite"
WSGIApplicationGroup %{GLOBAL}
<Directory f:/pythonproject/file-manage/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static f:/pythonproject/file-manage/mysite/static
<Directory f:/pythonproject/file-manage/mysite/static>
AllowOverride None
Options None
Require all granted
</Directory>
修改后用httpd -t
测试是否解析正确,如不正确,在logs/error.log中查看报错信息
配置好后,安装apache服务:
httpd -k install -n 服务名
卸载服务:sc delete 服务名
问题
导入win32api时如何修复“ ImportError:DLL加载失败”
进入虚拟环境或python目录,执行
python Scripts/pywin32_postinstall.py -install
如果不能解决,则尝试
pip show pywin32
pip install pywin32==300 --upgrade
首页一直转圈圈
httpd.conf文件加入WSGIApplicationGroup %{GLOBAL}
报错populate() isn’t reentrant
将venv/lib/site-packages/django/apps/registry.py中83行
raise RuntimeError("populate() isn't reentrant")
修改为
self.app_configs = {}
遇到error.log乱码
s = b'\xe6\x89\xbe\xe4\xb8\x8d\xe5\x88\xb0\xe6\x8c\x87\xe5\xae\x9a\xe7\x9a\x84\xe7\xa8\x8b\xe5\xba\x8f\xe3\x80\x82'
print(s.decode('utf-8'))
print(s.decode('gbk'))
No module named ‘encodings’
设置环境变量
PYTHONHOME="D:\python"
PYTHONPATH="D:\python\Lib"
python程序报错
有可能是apache权限不足,修改apache服务登录用户为管理员账户