uv icon indicating copy to clipboard operation
uv copied to clipboard

Selecting .venv/bin/python as an active interpreter in VSCode doesn't enable IDE features

Open oulianov opened this issue 1 year ago • 100 comments

Maintainer edit: Please set python.usePythonEnvironmentsExtension: true and check if the problem persists. See https://github.com/astral-sh/uv/issues/9637#issuecomment-3197523231 for more detail.


Hello,

I develop my Python app with uv to handle dependencies. I want to benefit from intellisense, type hints, mypy and ruff in VSCode while I develop my app. VSCode is the most popular IDE for Python developers.

Usually, I create the a virtual env with python -m venv. I then select the virtual env in VSCode as an "Active Interpreter". This adds support from all the VSCode features mentioned.

With uv, a folder .venv is created. However, when I select this .venv as an active interpreter in VSCode, nothing changes in my editor. Intellisense, type hints, and mypy don't work. Installed modules are not found. Custom modules are not found either.

When I run "Reload Window", this results in a toast on the bottom right "Reactivating terminals" that never completes.

Restarting VSCode with the config doesn't make it work.

This means for now I need to have multiple virtual environment running. One for uv, another for development. This voids the usefulness of uv for package management.

How to make uv virtual environments work with VSCode?


[EDIT] HERE IS A WORKAROUND! Here's a foolproof technique my buddy @Jeerhz showed me to select a uv .venv as an active interpreter in vscode.

  1. First, copy the absolute path to the .venv. Not to the /bin/python, only the .venv folder.
Image
  1. Do Cmd+Shift+P, then look for "Python: Select interpreter". Press Enter. Select the option: "Enter interpreter path".
Image
  1. Now in this field you copy paste the absolute path to the .venv folder.
Image Image

Press enter and now you have the right Python environment with all the dependencies.

Selecting .venv as an active interpreter in VSCode works. But selecting .venv/bin/python doesn't.


Recommendation: use an extension like teticio.python-envy to automatically set the interpreter path based on the file you're currently looking at, compare https://github.com/astral-sh/uv/issues/9637#issuecomment-2813097995 . This is what I currently use and it has been working quite well in my monorepo setup.

oulianov avatar Dec 04 '24 13:12 oulianov

I don't know what to say here, this is pretty basic functionality and I cannot reproduce it

❯ uv init example
Initialized project `example` at `/Users/zb/workspace/uv/example`
❯ code example
❯ cd example
❯ uv add httpx
Using CPython 3.12.7
Creating virtual environment at: .venv
Resolved 8 packages in 113ms
Installed 7 packages in 13ms
 + anyio==4.6.2.post1
 + certifi==2024.8.30
 + h11==0.14.0
 + httpcore==1.0.7
 + httpx==0.28.0
 + idna==3.10
 + sniffio==1.3.1

Image

Can you share more details?

zanieb avatar Dec 04 '24 17:12 zanieb

Hello, Zanieb!

OK, this is a relief to know this is supposed to work. Here are more details:

Following the same steps as you, this is what I get after running uv add httpx in VSCode : "Can't resolve httpx import". This is ok : I need to activate the python environment. Image

I do Command+Shift+P. This lists the interpreters, but the local .venv doesn't show up. This is alright, I can still enter the path to it manually. Image

Then, I manually select the path to the .venv created by uv: .venv/bin/python by clicking on "Enter Interpreter path". This doesn't enable intellisense.
I can select any other environment (either conda, either created with python -m venv) normally. A message saying "Reactivating terminals" in the bottom left runs infinitely. Reloading the window doesn't stop this. I would need to quit and restart vscode. Image

If I try to do uv run hello.py in the VSCode terminal, the process hangs and never completes. If I Ctrl+C to stop the execution and instead do python hello.py, the program runs normally.

Running uv run hello.py in a new terminal results in this:

error: Querying Python at `/Users/nicolasoulianov/test/example/.venv/bin/python3` failed with exit status signal: 9 (SIGKILL)
--- stdout:

--- stderr:

---

This error occurs whether VSCode is open or not. Image

When I go again to select an interpreter, VSCode tells me that I'm using ~/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/bin/python. Image

  • I have conda 23.7.4 installed. I'm using MacOS Sonoma 14.6.1 on a MacBook M3 Pro.
  • A colleague has the same problem (he use a similar machine to mine).

What else can I share with you to help you further?

oulianov avatar Dec 04 '24 23:12 oulianov

I think I figured this out: the uv .venv can't be selected in VSCode when the .venv is not at the root of the VSCode workspace.

For example, this doesn't work: .venv is in example/.venv Image

However, this works: .venv is at the root of the VSCode workspace. Image

This is pretty weird. I'm working with a lot of monorepo so I'm used to have multiple Python projects with different configs in the same VSCode window.

Do you know of a way to circumvent this behavior ? So that I can still have intellisense, even if the uv .venv is not at the root of the VSCode workspace ?

oulianov avatar Dec 04 '24 23:12 oulianov

That's.. very weird. I'm not sure what would cause that.

Perhaps we should narrow down uv run python failing? Can you produce that consistently?

Can you invoke Python directly? e.g.

❯ uv python find --python-preference only-managed --system
/Users/zb/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/bin/python3.12
❯ /Users/zb/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/bin/python3.12 --version
Python 3.12.7

Can you create a virtual environment with it and use it?

❯ /Users/zb/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/bin/python3.12 -m venv ./venv
❯ ./venv/bin/python --version
Python 3.12.7

zanieb avatar Dec 05 '24 01:12 zanieb

Unfortunately, I can't reproduce the issue with just uv run python

I can invoke Python directly. I can create venv with it and use it.

nicolasoulianov@MacBook-Pro-de-Nicolas-2 teleop % uv python find --python-preference only-managed --system
/Users/nicolasoulianov/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/bin/python3.10
nicolasoulianov@MacBook-Pro-de-Nicolas-2 teleop % /Users/nicolasoulianov/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/bin/python3.10 --version
Python 3.10.15
nicolasoulianov@MacBook-Pro-de-Nicolas-2 teleop % /Users/nicolasoulianov/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/bin/python3.10 -m venv ./venv2
nicolasoulianov@MacBook-Pro-de-Nicolas-2 teleop % ./venv2/bin/python --version
Python 3.10.15

Here is another piece of information. When I select the interpreter in .venv/bin/python, I see that I select a shortcut towards the true interpreter (localized at /Users/nicolasoulianov/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/bin/python3.10). Maybe this information is not enough for VSCode to make sense of the dependencies? Image

Do you work with uv-managed .venv in subfolders in VSCode ? Or you know someone that does ? How does Intellisense work for you and them ?

oulianov avatar Dec 05 '24 10:12 oulianov

I opened a new VSCode window and tried again activating the .venv environment. Now, when I run

/Users/nicolasoulianov/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/bin/python3.10 --version

The program hangs. I can't even Ctrl+C to stop it.

Image

I have the infinite "Reactivating terminals" loading bar Image

I need to restart my computer to be able to use everything normally again.

oulianov avatar Dec 05 '24 10:12 oulianov

Does everything work if you do uv venv --python-preference only-system to skip using our managed interpreters?

Do you have an antivirus or similar?

Can you look at the VSCode Python debug logs?

zanieb avatar Dec 05 '24 15:12 zanieb

I enabled VSCode Python debug logs.

I don't have an antivirus. However, I'm running Vanta Agent and 1Password.

Using managed venv

If I select the managed uv .venv/bin/python as an active interpreter, I have a null error code.

2024-12-05 16:37:48.507 [info] > ~/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/bin/python3.10 -I ~/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/interpreterInfo.py
2024-12-05 16:37:48.511 [error] Error: Command failed: /Users/nicolasoulianov/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/bin/python3.10 -I /Users/nicolasoulianov/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py /Users/nicolasoulianov/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/interpreterInfo.py

    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at ChildProcess.exithandler (node:child_process:423:12)
    at ChildProcess.emit (node:events:531:35)
    at maybeClose (node:internal/child_process:1105:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:519:28)
    at Pipe.<anonymous> (node:net:339:12) {
  code: null,
  killed: false,
  signal: 'SIGKILL',
  cmd: '/Users/nicolasoulianov/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/bin/python3.10 -I /Users/nicolasoulianov/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py /Users/nicolasoulianov/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/interpreterInfo.py'
}
2024-12-05 16:37:50.513 [info] > ~/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/bin/python3.10 -I ~/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/interpreterInfo.py

I have then the "Reactivating terminals error"

Running

/Users/nicolasoulianov/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/bin/python3.10

In a terminal hangs the process. It doesn't show the Python console.

Creating a new venv

I create a .venv with uv venv --python-preference only-system to skip the managed interpreters.

I try to select it but nothing happens, not even an error message. I delete the conda environment I had which was named teleop, the same name as the folder containing the .venv.

I try again to select the .venv. Now, I have an error when selecting it. The error code is 126. I see "Permission denied". I also have a visible error toaster in VSCode. This is the first time it has been the case.

Image

2024-12-05 16:50:38.156 [error] Error: Command failed: /Users/nicolasoulianov/robots/robots/teleop/.venv/bin/python -I /Users/nicolasoulianov/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py /Users/nicolasoulianov/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/interpreterInfo.py
/bin/sh: /Users/nicolasoulianov/robots/robots/teleop/.venv/bin/python: Permission denied

    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at ChildProcess.exithandler (node:child_process:423:12)
    at ChildProcess.emit (node:events:531:35)
    at maybeClose (node:internal/child_process:1105:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:519:28)
    at Pipe.<anonymous> (node:net:339:12) {
  code: 126,
  killed: false,
  signal: null,
  cmd: '/Users/nicolasoulianov/robots/robots/teleop/.venv/bin/python -I /Users/nicolasoulianov/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py /Users/nicolasoulianov/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/interpreterInfo.py'

I try to run the Python interpreter in my console, and I get permission denied as well.

(teleop) (base) nicolasoulianov@MacBook-Pro-de-Nicolas-2 teleop % /Users/nicolasoulianov/robots/robots/teleop/.venv/bin/python
zsh: permission denied: /Users/nicolasoulianov/robots/robots/teleop/.venv/bin/python

I then change the authorizations of the .venv folder

sudo chmod -R 777 .venv

I run this command. It doesn't show anything in the command line.

 /Users/nicolasoulianov/robots/robots/teleop/.venv/bin/python

I have this error in the VSCode Python extension logs : failed to parse json

2024-12-05 16:59:22.698 [info] > ./teleop/.venv/bin/python -I ~/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/interpreterInfo.py
2024-12-05 16:59:22.701 [error] Failed to parse interpreter information for >> /Users/nicolasoulianov/robots/robots/teleop/.venv/bin/python -I /Users/nicolasoulianov/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py /Users/nicolasoulianov/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/interpreterInfo.py << with Error: python /Users/nicolasoulianov/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/interpreterInfo.py returned bad JSON () (SyntaxError: Unexpected end of JSON input)

Could this be an authorization issue with uv, my home folder, MacOS "security features", or something else ?🤔

oulianov avatar Dec 05 '24 16:12 oulianov

Have you tried updating VSCode to the latest version?

zanieb avatar Dec 05 '24 23:12 zanieb

I am on the VSCode latest version available

Image

Version: 1.95.3 (Universal)
Commit: f1a4fb101478ce6ec82fe9627c43efbf9e98c813
Date: 2024-11-13T14:50:04.152Z (3 wks ago)
Electron: 32.2.1
ElectronBuildId: 10427718
Chromium: 128.0.6613.186
Node.js: 20.18.0
V8: 12.8.374.38-electron.0
OS: Darwin arm64 23.6.0

oulianov avatar Dec 06 '24 10:12 oulianov

I'm sorry I'm out of suggestions here if you've updated VS Code and restarted it. We can't reproduce this problem.

For reference, I'm using the exact same build

Version: 1.95.3
Commit: f1a4fb101478ce6ec82fe9627c43efbf9e98c813
Date: 2024-11-13T14:50:04.152Z (3 wks ago)
Electron: 32.2.1
ElectronBuildId: 10427718
Chromium: 128.0.6613.186
Node.js: 20.18.0
V8: 12.8.374.38-electron.0
OS: Darwin arm64 23.5.0

zanieb avatar Dec 06 '24 14:12 zanieb

Hmm... This is all very strange.

I assume there must something cursed about my setup :

  • multiple .venv in a single VSCode workspace
  • nested python projects

I'll simplify my setup and keep you posted.

In the meanwhile, using an additional .venv for development and uv for deployment works good enough.

Thank you for the support!

oulianov avatar Dec 10 '24 08:12 oulianov

I'd just like to confirm that I'm using the following setup with success:

  • Python monorepo
  • Single uv workspace with multiple projects
  • using direnv to set UV_PROJECT_ENVIRONMENT within each project directory such that uv creates a separate .venv in the project root instead of the workspace root
  • VSCode opened to the workspace directory -> manually selecting the appropriate .venv -> Reload Window
  • Testing integration also works so long as I point VSCode to the specific pyproject.toml which houses the pytest config for the specific project.

NellyWhads avatar Dec 18 '24 18:12 NellyWhads

I have the same issues as @oulianov, I have a large monorepo and each python project is independent, we don't use the workspaces feature yet.

When selecting the interpreter VS Code follows the symlinks back to ~/.local/share/uv/python/... without access to any of the libraries I have installed.

cam-at-tactiq avatar Jan 05 '25 22:01 cam-at-tactiq

Can someone please share a minimal project this reproduces on and a script to setup the environments?

zanieb avatar Jan 05 '25 22:01 zanieb

I can reproduce this locally in my development monorepo. Here's a minimal repro. If there's any other information I can provide, let me know.

  • uv version: 0.5.24
  • VSCode version: 1.96.4
  • mspython-python extension version: 2024.22.2
  • ms-python.vscode-pylance extension version: 2025.1.101

Instructions:

  1. Run ./setup.sh
  2. Open VSCode
  3. In VSCode, open projects/project1/hello.py
  4. Run Python > Select Interpreter
  5. Enter Interpreter Path...
  6. Find...
  7. Select path/to/projects/project1/.venv/bin/python
  8. Note that Pylance reports Import "urllib3" could not be resolved
  9. Reload Window
  10. Note that Pylance still reports Import "urllib3" could not be resolved
  11. Rinse and repeat with project2/hello.py

setup.sh:

root=$(realpath "$(dirname "$0")")

cd $root
mkdir -p projects/project1
cd projects/project1
uv python find --python-preference only-managed --system
uv init --no-workspace --python-preference only-managed
uv add urllib3
uv sync
cat <<EOF > hello.py
import urllib3
print("p1", urllib3.__file__)
EOF
uv run hello.py
echo ""

cd $root
mkdir -p projects/project2
cd projects/project2
uv python find --python-preference only-system --system
uv init --no-workspace --python-preference only-system
uv add python-dateutil
uv sync
cat <<EOF > hello.py
import dateutil
print("p2", dateutil.__file__)
EOF
uv run hello.py
echo ""

Terminal output:

/Users/chris/.local/share/uv/python/cpython-3.10.14-macos-aarch64-none/bin/python3.10
Initialized project `project1`
Using CPython 3.10.14
Creating virtual environment at: .venv
Resolved 2 packages in 59ms
Installed 1 package in 3ms
 + urllib3==2.3.0
Resolved 2 packages in 0.20ms
Audited 1 package in 0.01ms
p1 /Users/chris/code/uv-monorepo-vscode/projects/project1/.venv/lib/python3.10/site-packages/urllib3/__init__.py

/Users/chris/.local/share/mise/installs/python/3.10.15/bin/python
Initialized project `project2`
Using CPython 3.10.14
Creating virtual environment at: .venv
Resolved 3 packages in 44ms
Installed 2 packages in 2ms
 + python-dateutil==2.9.0.post0
 + six==1.17.0
Resolved 3 packages in 0.22ms
Audited 2 packages in 0.00ms
p2 /Users/chris/code/uv-monorepo-vscode/projects/project2/.venv/lib/python3.10/site-packages/dateutil/__init__.py

Also, I intermittently get this error in the Python logs in VSCode if I reload the window a few times:

2025-01-28 13:02:22.140 [info] Native locator: Refresh started
2025-01-28 13:02:22.140 [info] Native locator: Refresh started
2025-01-28 13:02:22.362 [info] > pyenv which python
2025-01-28 13:02:22.362 [info] cwd: .
2025-01-28 13:02:22.482 [info] > conda info --json
2025-01-28 13:02:22.493 [info] Poetry environment manager found at: /Users/chris/.local/pipx/venvs/poetry/bin/poetry
2025-01-28 13:02:22.501 [info] Conda environment manager found at: /opt/homebrew/Caskroom/miniconda/base/bin/conda
2025-01-28 13:02:22.504 [info] Python interpreter path: ~/.local/share/uv/python/cpython-3.10.14-macos-aarch64-none/bin/python
2025-01-28 13:02:23.364 [info] Starting Pylance language server.
2025-01-28 13:02:23.500 [info] Native locator: Refresh finished in 1578 ms
2025-01-28 13:02:28.119 [error] Active interpreter type is detected as Unknown {"id":"/Users/chris/.local/share/uv/python/cpython-3.10.14-macos-aarch64-none/bin/python","sysPrefix":"/Users/chris/.local/share/uv/python/cpython-3.10.14-macos-aarch64-none","envType":"Unknown","envName":"","envPath":"/Users/chris/.local/share/uv/python/cpython-3.10.14-macos-aarch64-none/bin/python","path":"/Users/chris/.local/share/uv/python/cpython-3.10.14-macos-aarch64-none/bin/python","architecture":3,"sysVersion":"","version":{"raw":"3.10.14","major":3,"minor":10,"patch":14,"build":[],"prerelease":[]},"displayName":"Python 3.10.14","detailedDisplayName":"Python 3.10.14"}

chanderson0 avatar Jan 28 '25 18:01 chanderson0

@chanderson0 thanks for all the details. Unfortunately, I followed your instructions and could not reproduce the problem.

zanieb avatar Jan 28 '25 19:01 zanieb

Thanks for the quick reply!

After playing with a lot more, I think part of the issue is that there's a difference in (a) using the GUI to select a Python interpreter path (which appears to resolve symlinks and therefore breaks any link to the actual local venv) and entering either (b) an absolute path or (c) a path relative to the workspace root (which appears to not resolve symlinks, and does work as intended).

So maybe the resolution is to always enter an actual path and not the filesystem picker as in (b) and (c). It's working for me, anyway! If I get a chance, I'll open an issue with Pylance, since that's a confusing behavior.

chanderson0 avatar Jan 28 '25 20:01 chanderson0

I was using Ctrl-P to invoke Python > Select Interpreter then entering an absolute interpreter path.

I honestly don't know how to get a filesystem picker to show up :D

zanieb avatar Jan 28 '25 20:01 zanieb

Coming back to this issue. Here's a foolproof technique my buddy @Jeerhz showed me to select a uv .venv as an active interpreter in vscode.

  1. First, copy the absolute path to the .venv. Not to the /bin/python, only the .venv folder.
Image
  1. Do Cmd+Shift+P, then look for "Python: Select interpreter". Press Enter. Select the option: "Enter interpreter path".
Image
  1. Now in this field you copy paste the absolute path to the .venv folder.
Image Image

Press enter and now you have the right Python environment with all the dependencies.

Selecting .venv as an active interpreter in VSCode works. But selecting .venv/bin/python doesn't.

It would be nice if we didn't have to do all these shenanigans. In a monorepo, I switch from python project and dependencies all the time. The current procedure is pretty painful, not documented, and not trivial.

It would be great to have all the .venv show up in the interpreter list. Even better, the active interpreter could switch automatically depending on the opened file.

@zanieb are there any plans to improve the uv experience in vscode?

oulianov avatar Jan 31 '25 03:01 oulianov

I cannot reproduce this problem (e.g., by entering the full path to the Python interpreter). Hence, I cannot figure out how to improve the experience.

We need more information to understand what's going on.

Does this only occur with uv venv? Does this not occur with python -m venv?

Does this only occur with uv-managed Python versions? Does this not occur with uv venv --python-preference only-system vs uv venv --python-preference only-managed?

Frankly, these sounds like VS Code bugs that we won't really be able to fix but I'm happy to try regardless.

zanieb avatar Jan 31 '25 18:01 zanieb

To be clear, I agree that something must be wrong because we keep hearing reports. I just can't tell what exactly is wrong since each time I try to reproduce, it works fine for me.

zanieb avatar Jan 31 '25 18:01 zanieb

I'm pretty sure that the issue originally highlighted in this thread (and the one I was facing) derives from the VSCode behavior that resolves symlinks when you open the file picker during interpreter selection. That's probably on the VSCode side to fix.

But there may be something additionally happening where uv venvs aren't being picked up automatically, and so someone would need to either (a) add uv support into https://github.com/microsoft/python-environment-tools and https://github.com/microsoft/vscode-python (see e.g. https://github.com/microsoft/vscode-python/pull/24442 and https://github.com/microsoft/python-environment-tools/pull/172 for Pixi doing this recently) or (b) figure out why the existing virtualenv locator isn't working against these environments.

chanderson0 avatar Jan 31 '25 19:01 chanderson0

I'm pretty sure that the issue originally highlighted in this thread (and the one I was facing) derives from the VSCode behavior that resolves symlinks when you open the file picker during interpreter selection. That's probably on the VSCode side to fix.

I'm surprised this hasn't come up before as symbolically linked interpreters in virtual environments are very common on Unix.

We use standards-compliant virtual environments and these should be found by their normal locator since it includes our default name of .venv? https://github.com/microsoft/python-environment-tools/blob/1abe5cec5ebfbe97ca71746a4cfc7fe89bddf8e0/crates/pet/src/find.rs#L262

zanieb avatar Jan 31 '25 20:01 zanieb

To throw another loop in this - our setup is extremely similar and we are able to use the regular VSCode Interpreter selector. We're running the latest VSCode and I've tried it on the latest Cursor. Works stably on MacOS, and on remote development hosts both inside and outside devcontainers with no issues.

NellyWhads avatar Feb 04 '25 02:02 NellyWhads

I encountered this issue just now with my tauri setup. Vscode doesn't recognise the path in .venv created by default.

cloudycotton avatar Feb 05 '25 15:02 cloudycotton

Hi. I'm also running into this. I have a .venv in a scripts/ subfolder of my vscode project:

scripts/.venv/bin/python@ -> /opt/homebrew/Caskroom/miniconda/base/bin/python3

Now if I add the interpreter via the vscode UI, it seems to be adding the target path and think I'm in the base conda environment. But if manually specify <my_repo>/scripts/.venv/bin/python in in the vscode popup to find the interpreter (i.e. without going through macOS Finder), then it establishes the correct venv.

Seems to be more an issue with vscode than uv I would say.

jdumas avatar Feb 07 '25 01:02 jdumas

I’ve noticed another issue: when I install dependencies and package a script with uvx pyinstaller main.py, the dependencies aren’t bundled as expected. This might be related.

I'm on latest Mac OS build.

cloudycotton avatar Feb 07 '25 02:02 cloudycotton

Sorry, I haven't read the full thread, but I will add something in case it helps. I don't experience this issue with VSCode, but whenever my VSCode was misconfigured was because it was not using the workspace properly: https://code.visualstudio.com/docs/editor/workspaces/workspaces

If you have a single-folder workspace you open your workspace with Open Folder, if you have a monorepo, you select open workspace from file, and you need proper settings.

I have a single-folder repo and everything shows nicely for me using uv. If you haven't selected a workspace properly, selecting an interpreter may have issues, because VSCode may have trouble using a .venv to source files.

jzazo avatar Feb 12 '25 15:02 jzazo

Just adding my issue to this thread. It seemed like virtual environments were working fine in vscode for a long time, now I experience the same issue with them not activating when opening the terminal. I tried the tips about typing-out the .venv path as described above, without luck. I'm managing my environments with uv, in separate project folders within a monorepo workspace.

Maybe this is a new bit of information:

I'm using macOS, with zsh, OhMyZsh, and the powerlevel10k theme (all this worked fine, until just recently). Not sure if others with this issue have the same setup.

geozeke avatar Feb 19 '25 19:02 geozeke