Call pip from subprocess

Trying to call pip from a python script to install a package in a virtual env.

    opt = '--dry-run,' if dry_run else ''
    args = f'{project.venv_path}/bin/python3 -m pip install {opt} --report - django'

        completedProcess =,
        project.django_requirements = completedProcess.stdout
        return completedProcess.returncode
    except subprocess.CalledProcessError as e:
        print('subprocess error for pip install django')
        return e.returncode

I keep getting the following error message : no such option --dry-run
or no such option --report depending of the order of the option in args !..

What did I miss?

Have you checked that your subprocess is running the latest version of pip? The options you’re using were only just introduced, so if your project venv has an old copy of pip, they will not be recognised.

Yes I checked. But may be my check is no good. :grinning:
This is why I tried to changed the order of the options. is the dry-run also a recent option?

Why is there a comma after —dry-run?

Also, shlex.split() isn’t your friend here, if project.venv_path has a space in it. You’re better off building up an array of strings yourself, and not splitting.

well thanks a lot; solved ; there were a version problem and a shlex.split!..