[Python] How can I create user environment variables for a non-admin user account?

Discussão em 'Python' iniciado por Stack, Outubro 25, 2024.

  1. Stack

    Stack Membro Participativo

    I'm on Windows 10, using python with an API token. I want to store that token as an environment variable outside of my code, then access it in python like this:

    import os
    token = os.environ['TOKEN_NAME']


    When I set the variable as a user environment variable, I can only access it via my admin account. Ex. TOKEN_ONE in the image link below.

    When I set it as a system environment variable, I can additionally access via my non-admin account. Ex. TOKEN_TWO in the image link below.

    Where it says "User variables for" at the top of the below image - the blacked out portion is my admin username- and I can't change it to set to my non admin username.

    My path: Control Panel ⟶ System and Security ⟶ System ⟶ Advanced System Settings (asks for admin password) ⟶ Environment Variables

    Environment Variables Settings

    [​IMG]


    Is there a way to make a user environment variable, accessible from a user account, that is not system wide?

    By accessible, I mean it shows up when I type set into terminal.


    My use case doesn't necessarily need it to be local to the user, but it would be good to know how to do that if possible.

    If not, I will learn more about virtual environments.

    Thank you.

    Continue reading...

Compartilhe esta Página