Open kdheepak opened 1 month ago
Hmm, that's a surprising one. What does where ipython
return?
Here's the output of where ipython
:
$ where ipython
C:\Users\USERNAME\gitrepos\project-foo\.venv\Scripts\ipython.exe
C:\Users\USERNAME\miniforge3\Scripts\ipython.exe
fwiw, I'm using git bash. And which ipython
returns the path/to/.venv/Scripts/ipython
as well.
Oddly enough, uv run ipython
doesn't give the warning.
I verified that this doesn't happen on Linux.
@kdheepak you could try to debug the issue by putting some print statements into
C:\Users\USERNAME\gitrepos\project-foo\.venv\Lib\site-packages\IPython\core\interactiveshell.py
Specifically, it would be interesting to print out the value of variables paths
and p_env
in function init_virtualenv
to find out why do following condition evaluates to False
instead of True
as it should.
if any(p_venv == p.parents[1] for p in paths):
# Our exe is inside or has access to the virtualenv, don't need to do anything.
return
I added the following print functions:
print(f"{p_venv = }")
print(f"{p.parents[1] = }")
print(f"{p.parents = }")
print(f"{paths = }")
if any(p_venv == p.parents[1] for p in paths):
# Our exe is inside or has access to the virtualenv, don't need to do anything.
return
Here's the output:
p_venv = WindowsPath('/c/Users/USERNAME/gitrepos/project-foo/.venv')
p.parents[1] = WindowsPath('C:/Users/USERNAME/gitrepos/project-foo/.venv')
p.parents = <WindowsPath.parents>
paths = [WindowsPath('C:/Users/USERNAME/gitrepos/project-foo/.venv/Scripts/python.exe')]
The issue is because of Unix paths and Windows paths being compared. Adding a .resolve()
doesn't appear like it'll solve it:
Cannot reproduce on Git Bash with version below:
$ uname -a
MINGW64_NT-10.0-19045 DESKTOP-14RM0I9 3.4.10-87d57229.x86_64 2024-02-14 20:17 UTC x86_64 Msys
Could you give more details in your virtualenv? Seems that your MSYS2 in Git Bash does not convert file paths presented in environment variables, where it should by default. Local result:
(testuv) ~/Documents/testuv
$ echo $VIRTUAL_ENV
/c/Users/y5/Documents/testuv/.venv
(testuv) ~/Documents/testuv
$ python -c 'import os; print(os.environ["VIRTUAL_ENV"])'
C:/Users/y5/Documents/testuv/.venv
Mine does the same thing:
$ echo $VIRTUAL_ENV
/c/Users/USERNAME/gitrepos/project-foo/.venv
$ python -c 'import os; print(os.environ["VIRTUAL_ENV"])'
C:/Users/USERNAME/gitrepos/project-foo/.venv
$ uname -a
MINGW64_NT-10.0-19045 XXXXXXX 3.4.10-2e2ef940.x86_64 2024-07-09 21:35 UTC x86_64 Msys
$ which uv
/c/Users/USERNAME/.cargo/bin/uv
$ deactivate
$ which python
/c/Users/USERNAME/miniforge3/python
On Windows, after running the following:
I get a warning:
This is with the latest version of
uv
: