uv: vscode trying but failing to use my uv venv
I’m pretty sure this is a bug with vscode’s integrated terminal, not uv, but after getting no answers from questions posted at stack overflow and on vscode’s github a month ago, figured I’d take a flier on seeing if anyone on uv’s side has any advice? I’d love to use uv but this is currently my blocker:
I have the following code in my main.py:
import pymupdf
print(f"pymupdf version is: {pymupdf.__version__}")
I can create a python3.12 environment with pymupdf installed and run it from my (kubuntu24.04) shell without issues, with the following commands (showing shell log after each >command):
>uv --version
uv 0.4.17
>uv init --no-pin-python
Initialized project `askliz2`
>uv venv --python 3.12.6
Using CPython 3.12.6
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
>source .venv/bin/activate
askliz2>uv add pymupdf
Resolved 3 packages in 281ms
Installed 2 packages in 11ms
+ pymupdf==1.24.10
+ pymupdfb==1.24.10
askliz2>python main.py
pymupdf version is: 1.24.10
However, when I launch vscode from this folder with my uv venv activated with code ., and then highlight the line import pymupdf and hit shift+enter to run it in the integrated terminal, I get the following vscode integrated terminal output:
/home/max/askliz2/.venv/bin/python
Python 3.12.6 (main, Sep 9 2024, 22:11:19) [Clang 18.1.8 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
]633;E;exit()]633;D;0]633;A>>> ]633;B]633;Cimport pymupdf
]633;E;import pymupdf]633;D;0]633;A>>> ]633;B]633;C
Things I’ve tried so far:
- upgrading uv version
- hosing and re-installing vscode
- installing different python versions (e.g. 3.12.0, 3.12.6, 3.9)
- right-clicking to
clear terminalandkill terminaland then trying again
When I use the command pallet to select python interpreter, it shows me it’s trying to use Python 3.12.6(‘.venv’) ./.venv/bin/python, as it should be, and as the vscode integrated logs above already indicate.
VS Code version: Code 1.93.1 (38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40, 2024-09-11T17:20:05.685Z) OS version: Linux x64 6.10.6-061006-generic
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 15 (5 by maintainers)
when you select the interpreter, in vscode make sure you pass down the interpreter path manually, because if passing via ui (finder/windows explorer) vscode will set the symlink to uv system python causing the link to fail.
@RedHeartSecretMan where do you set this? I’m facing the same issue as @MaxPowerWasTaken. Thank you 👍
@marty0678 this is how I solved it.
binfolder and pressedCopy Path.I had the same problem migrating from the conda and pip habit. Setting up python plug-ins in vs code The following two configurations may work:
Python: Venv Path
Python: Venv Folders
You can try.
Tried migrating to uv today and got the same thing. Even setting the path manually, I can’t get VsCode to activate it. Will just go back to poetry for now, unfortunately.
This just saved me after 30 mins of fiddling with different settings. Thanks!
yes, it works.