Python subprocess can't modify environment variables

Eric's Avatar


05 Aug, 2018 07:56 PM

I'm trying to build a collection of software using a Python script that executes various commands using Python's subprocess module and check_call: subprocess.check_call( command, shell = True, env = environment ). The "command" and "environment" variables are testing to be working correctly on multiple other machines so I think that shouldn't be the problem.

When there are environment variables, it looks like they don't get correctly setup in the running environment. For example, if the command above is echo %PATH% and the PATH has been modified to include a directory the build needs to succeed, the echo command doesn't show it being included.

It looks like AppVeyor is preventing modification of the environment through Python's subprocess module, does that sound correct? If so, is there a way to get around that? I'm building a number of packages that rely on having environment variables set up properly and the environment varies from one package to the next so I can't use a common setup across the whole project.

Any tips?

  1. Support Staff 1 Posted by Owen McDonnell on 06 Aug, 2018 12:45 AM

    Owen McDonnell's Avatar

    I'm a little unclear whether you are wondering if AppVeyor is preventing subprocess from modifying environment or if the environment set up in your appveyor.yml configuration is not present from a subprocess call.

    If it's the latter, then that seems unsurprising. Maybe you could try setting your environment variables with

    - cmd: SETX MY_ENV_VAR env_var_value
    to make them present in the subprocess?
  2. Ilya Finkelshteyn closed this discussion on 06 Oct, 2018 09:00 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac