简体   繁体   中英

Why does VSCode not detect venv if the venv folder is installed inside a subdirectory?

I have been working with FastAPI and when done alone, venv works just fine with VSCode.

If I create a full-stack app the editor does not detect it (defaults to regular Python 3.9.4) and some Python imports cannot be found. I try looking for it and venv does not appear. It doesn't matter if I already activated it (the little venv icon appears on the terminal).

This is how the folder structure looks simplified:

full-stack-app

  • .git
  • frontend
  • backend
    • main.py
    • venv

I even tried running code. on the main directory as some suggested in other answers and no go (just Python 3.9.4. However, if I cd into backend and then run code. the interpreter defaults to the correct venv.

What is the correct practice for such a situation so that I can create a full-stack app and open the project at the top level without any trouble from venv?

Sorry, I test it locally, but it can detect the subfolder virtual environment.

If it still does not work, you can set python.venvPath in the User settings.json file:

Virtual environments located in the folder identified by the python.venvPath setting (see General settings), which can contain multiple virtual environments. The extension looks for virtual environments in the first-level subfolders of venvPath.

You can get more information from the official docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM