Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Niccolum opened this issue Jan 27, 2022 · 6 comments
Open

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

Niccolum opened this issue Jan 27, 2022 · 6 comments

Comments

@Niccolum
Copy link

Niccolum commented Jan 27, 2022

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

@Niccolum
Copy link
Author

Niccolum commented Jan 27, 2022

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.

@Niccolum Niccolum changed the title [Question] dotenv cli not used windows venv if it activate? [BUG] dotenv cli not used windows venv if it activated Jan 28, 2022
@Niccolum
Copy link
Author

UPD: crutch is working!

@Indiana3714
Copy link

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

@EliiseS
Copy link

EliiseS commented Mar 14, 2024

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

@MahrRah
Copy link

MahrRah commented Mar 14, 2024

Same issue here.

@Bajron
Copy link

Bajron commented Mar 15, 2024

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants