简体   繁体   中英

VSCode debugger not running inside virtual environment

I'm trying to debug my Django application within VSCode, but for some reason VSCode isn't running inside my virtualenv. I've tried multiple ways for it to work, but still no luck.

  1. I've set pythonpath to the path of the Pythonfile inside my virtualenv: "python.pythonPath": "/Users/username/documents/programmering/bq/env/bin/python3"

  2. I've tried selecting the Python file inside my virtual environment as the interpreter in VScode

  3. I've added the following line to my launch.json: "env": { "PYTHONPATH": "${workspaceRoot}"}

If I run the debugger and print sys.version and sys.path I'm getting the following prints:

SYS VERSION: 
3.9.7 (default, Oct 13 2021, 06:44:56) 
[Clang 12.0.0 (clang-1200.0.32.29)]

SYS PATH: 
['/Users/username/Documents/Programmering/bq/project/projectile', 

'/Users/username/Documents/Programmering/bq/project', 

'/usr/local/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', 

'/usr/local/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9', 

    '/usr/local/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload',

 '/usr/local/lib/python3.9/site-packages']

This is what my interpreters looks like, not that I've got pyenv installed and have run "pyenv global 3.9.7" to set a global version for python as well ass "pyenv local 3.6.9" inside my project folder, to have the latter python version active for my project.

Interpreters in VSCode

What I'm a bit puzzled about is that in the directories for the interpreter the path is to the pyenv version of python, and not the actual python version in the virtual environment, perhaps that can be the cause for the issue? How would I go around to fix that?

Simple answer - You need to open up VSCode inside the folder that contain both your virtual environment as well as you code files.

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