环境
操作系统:Windows 10
Python版本:3.6
虚拟环境:否
运行方式:runserver
操作系统:CentOS 7
Python 版本:3.7.8
虚拟环境:是
运行方式:宝塔面板 uWSGI + Nginx
功能逻辑
cwd
参数指定命令运行的路径,通过
stdin
、
stderr
、
stdout
参数获取命令执行的输出内容,通过
communicate()
等待命令执行完成。
Popen(
[python_env, 'manage.py', 'makemigrations'],
stdin=PIPE,
stderr=PIPE,
stdout=PIPE,
cwd=settings.BASE_DIR
)
out_2, err_2 = mig_call.communicate()
Git 仓库认证问题
git clone https://git.mrdoc.pro/MrDoc/MrDocPro.git
fatal: could not read Username for 'https://git.mrdoc.pro'
git config --global credential.helper store
uwsgi --ini uwsgi.ini

git clone https://{username}:{password}@git.mrdoc.pro/MrDoc/MrDocPro.git
Python 解释器路径问题
Python
:
python manage.py migrate
python
命令指向的也是 Python 2,就算将其指向到 Python3。
python
命令指向正确的 Python 解释器路径,州的先生使用了 Python 内置库
sys
提供的
executable
属性,这个属性会返回 Python 解释器的可执行二进制文件的绝对路径。


python
是不会错的了,结果又报出个错误来:
unable to load configuration from manage.py

uwsgi 就是当前的 python 解释器,因为它链接 libpython.so。获取 sys.executable 是不可能的,因为库本身没有硬编码的二进制路径。
uwsgi
结尾,就可以将其替换掉,如果是正常的Python解释器路径,就可以直接使用。
总结
本文分享自微信公众号 - 州的先生(zmister2016)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。