Skip to content

[BUG] dotenv cli not used windows venv if it activated #373

Open

Description

@Niccolum

I use vscode on windows

Command:

python -m venv venv
.venv\Scripts\activate
pip install python-dotenv[cli]
dotenv run -- python -c "import sys; print(sys.executable)"

Expected:
\path\to\venv\Scripts\python.exe

Real:
\path\to\system\python.exe

If needed more info - I will try to provide it ASAP.

Cc: @scad89 help to find this issue

System:
Windows 10.

python -V
Python 3.8.5

Activity

  1. Niccolum commented on Jan 27, 2022

    @Niccolum
    Author

    Found interesting issue in CPython about it
    https://bugs.python.org/issue38905

    Have you any ideas how to solve this?

    I have idea with one crutch:

    command = [
        sys.executable if s == "python" and os.name == "nt" else s 
        for s in command
    ]
    

    Somewhere before https://github.com/theskumar/python-dotenv/blob/master/src/dotenv/cli.py#L153

    But I didn't test this yet

    Also we can add check sys.version_info in this crutch, but i haven't all supported python version on windows. I see you have tox, so we can come up with test for that and add different OS in tox (platform parameter) for check it for that, if you support this change.

  2. changed the title [-][Question] dotenv cli not used windows venv if it activate?[/-] [+][BUG] dotenv cli not used windows venv if it activated[/+] on Jan 28, 2022
  3. Niccolum commented on Jan 29, 2022

    @Niccolum
    Author

    UPD: crutch is working!

  4. Indiana3714 commented on Sep 1, 2022

    @Indiana3714

    Any chance the fix above can be merged? (assuming it works)

  5. EliiseS commented on Mar 14, 2024

    @EliiseS

    Any fix for this? Still running into this issue in windows

  6. MahrRah commented on Mar 14, 2024

    @MahrRah

    Same issue here.

  7. Bajron commented on Mar 15, 2024

    @Bajron

    You can do something like that (assuming cmd.exe)

    dotenv run %VIRTUAL_ENV%\Scripts\python -c "import sys; print(sys.executable)"
    

    Current behavior is just Python behavior. Compare

    python -c "import sys; print(sys.executable)"
    

    and

    python -c "import subprocess; subprocess.run(['python','-c', 'import sys; print(sys.executable)'])"
    

    Also, see the warning in Popen documentation https://docs.python.org/3/library/subprocess.html#subprocess.Popen

    Following the suggestions in the warning I created a pull request #508 . I believe resolving against the PATH is what most of the users expect.
    You can try it with:

    pip install python-dotenv@git+https://github.com/Bajron/python-dotenv@dotenv-run-resolve-path-for-upstream[cli]
    

    Most likely you need to uninstall the old version first as the version string is still the same and pip might not apply the changes because of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions