从Django管理命令运行pip install

2024-06-16 06:12:48 发布

您现在位置:Python中文网/ 问答频道 /正文

让我知道,如果这个问题是显而易见的足够,也有重复的这个问题,我是失败的搜索事先。你知道吗

我正在尝试从Django管理命令运行pip install requirements/dev.txt。我有一个逻辑,就是如果缓存没有改变,不要尝试运行脚本pip ...。我想知道如何从DMC运行这个命令?你知道吗

用法:

python manage.py install_prepreqs
Cache is unchanged, skipping.... 

安装_预处理.py你知道吗

# I want to run `pip install requirements/dev.txt` with some additional logic. 

Tags: installpipdjangopydev命令txt脚本
5条回答

从Django内部运行pip可能不是一个愚蠢的主意,但是如果你愿意,那么就把自己击倒:djangos custom-management-commandspythons ^{} module

另请参见this post关于子流程模块。你知道吗

from django.core.management.base import BaseCommand, CommandError
import subprocess

class Command(BaseCommand):
    def handle(self, *args, **options):
        # check your precondition logic here
        # ... your code goes here ...

        if my_condition == True:
            subprocess.run(["ls", "-l"])

        # ... some more code goes here if you wish ...

相关问题 更多 >