gpt4 book ai didi

django - 怎么: django_manage in ansible with Python3

转载 作者:行者123 更新时间:2023-12-04 04:21:21 26 4
gpt4 key购买 nike

我正在关注 django manage.py 模块
http://docs.ansible.com/django_manage_module.html

例如我的一项任务看起来像 -

- name: Django migrate
django_manage: command=migrate
app_path={{app_path}}
settings={{django_settings}}
tags:
- django

这适用于 python2(默认在 ubuntu 中)但是当我尝试使用 python3-django 项目时它会抛出错误
failed: [123.456.200.000] => (item=school) => {"cmd": "python manage.py makemigrations --noinput school --settings=myproj.settings.production", "failed": true, "item": "school", "path": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games", "state": "absent", "syspath": ["/home/ubuntu/.ansible/tmp/ansible-tmp-1432039779.41-30449122707918", "/usr/lib/python2.7", "/usr/lib/python2.7/plat-x86_64-linux-gnu", "/usr/lib/python2.7/lib-tk", "/usr/lib/python2.7/lib-old", "/usr/lib/python2.7/lib-dynload", "/usr/local/lib/python2.7/dist-packages", "/usr/lib/python2.7/dist-packages"]}
msg:
:stderr: Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management

从这个错误看来,Ansible 默认使用 Python2。我们可以将其更改为 python3 或任何其他解决方法吗?

PS:pip freeze 确保已安装 django 1.8(对于使用 pip3 的 python3)

建议:
当我运行 ubuntu@ubuntu:/srv/myproj$ python3 manage.py migrate 它工作正常。所以我正在考虑直接传递命令
就像是
 - name: Django migrate
command: python3 manage.py migrate
tags:
- django

但是如何传递项目路径或 manage.py 文件的路径,只有一个选项可以传递设置,例如 --settings=myproject.settings.main

我们可以通过直接命令吗?

最佳答案

来自 Ansible 网站 http://docs.ansible.com/intro_installation.html

Python 3 is a slightly different language than Python 2 and most Python programs (including Ansible) are not switching over yet. However, some Linux distributions (Gentoo, Arch) may not have a Python 2.X interpreter installed by default. On those systems, you should install one, and set the ‘ansible_python_interpreter’ variable in inventory (see Inventory) to point at your 2.X Python. Distributions like Red Hat Enterprise Linux, CentOS, Fedora, and Ubuntu all have a 2.X interpreter installed by default and this does not apply to those distributions. This is also true of nearly all Unix systems. If you need to bootstrap these remote systems by installing Python 2.X, using the ‘raw’ module will be able to do it remotely.

关于django - 怎么: django_manage in ansible with Python3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30326654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com