python-dotenv
python-dotenv copied to clipboard
[BUG] dotenv cli not used windows venv if it activated
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
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.
UPD: crutch is working!
Any chance the fix above can be merged? (assuming it works)
Any fix for this? Still running into this issue in windows
Same issue here.
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.