-
Notifications
You must be signed in to change notification settings - Fork 2.3k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VSCode + debugging + poetry #5354
Comments
@finswimmer This might be related? |
Same issue here. This is my config: {
"version": "0.2.0",
"configurations": [
{
"name": "Pizzas service",
"type": "python",
"request": "launch",
"cwd": "${workspaceFolder}/backend/pizzas",
"module": "poetry",
"justMyCode": false,
"args": [
"run",
"uvicorn",
"src.main:app",
"--host",
"0.0.0.0",
"--port",
"8000",
"--reload"
]
}
]
} |
I FOUND A SOLUTION 😄 🥳Pre requirementsPoetry creates environments in a cache folder. So, first of all, this needs to be resolved. We need a more consistent and specific environment path. In my case I run: rm -rf ~/.cache/pypoetry/virtualenvs/pizzas-wQgq9NEZ-py3.10 After that, you need to specify a new environment directory: poetry config virtualenvs.in-project true This will create a new Because we created a new environment, we have to install the dependencies again. poetry install ConfigWith the prerequisite fixed, you can use a configuration similar to the following: {
"version": "0.2.0",
"configurations": [
{
"name": "Pizzas service",
"type": "python",
"request": "launch",
"pythonPath": "${workspaceFolder}/backend/pizzas/.venv/bin/python",
"cwd": "${workspaceFolder}/backend/pizzas",
"module": "uvicorn",
"justMyCode": false,
"args": [
"src.main:app",
"--host",
"0.0.0.0",
"--port",
"8000",
"--reload"
]
}
]
} |
@lucasvazq your solution solve my problems, congrats bro!!! |
thank you bro |
I my case, @lucasvazq solution worked with just the |
@lucasvazq, thank you so much! I followed your short "guide" and was able to set up debugging pytest in a poetry project. I just had to tweak the {
"version": "0.2.0",
"configurations": [
{
"name": "Python: run poetry pytest",
"type": "python",
"request": "launch",
"pythonPath": "${workspaceFolder}/.venv/Scripts/python.exe",
"cwd": "${workspaceFolder}",
"module": "pytest",
"args": [
],
"console": "integratedTerminal",
"justMyCode": false,
}
]
} |
You can also use
|
Another way to resolve this is to make your package have a module by creating
# __main__.py
from .project import real_main
# For Click, no arguments and the return value does not matter so do not use sys.exit(real_main())
real_main() Then in {
"configurations": [
{
"args": ["-v"],
"console": "integratedTerminal",
"module": "project",
"name": "project -v",
"request": "launch",
"showReturnValue": true,
"type": "python"
}
],
"version": "0.2.0"
} |
In my current test (as of Sep 25th 2023), below is still valid but we don't need to set this config anymore:
Also we don't need to set the "pythonPath" in the setting anymore (as VSCode does not support that anymore?).
|
What's the solution if we just want to run the .py file directly, but via Poetry? Poetry isn't actually installed in the venv, so I can't call it. Just trying to do whatever the equivalent of |
The only clean way I've found is to use A fairly lazy example would be to use an arbitrary env var such as PYDBG and drop this is your main file: if os.environ.get('PYDBG', None):
# This code will block execution until you run your Python: Remote Attach
port = 5678
host = 'localhost'
print(f"Blocking for remote attach for vscode {host} {port}")
import debugpy
debugpy.listen((host, port))
debugpy.wait_for_client() You'd need to {
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
],
"justMyCode": true
} |
It will be great if vscode supports something like below. {
"name": "run pipeline",
"request": "launch",
"runtimeArgs": [
"run",
"pipeline"
],
"runtimeVersion": "1.7",
"runtimeExecutable": "poetry",
"envFile": "${workspaceFolder}/.env",
"type": "python",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal"
}, This is similar to what node npm uses. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hi,
we use poetry and I like to use my poetry scripts as entry points for the debugging in vscode. Therefore, we use following vscode launch.json configurations:
The issue is that the debugging starts BUT exits early (after some seconds). In the middle of the process, everything stops. This is the case for all our code which is run via poetry.
If we run the python code manually without the
poetry run
command, but in a poetry shell withpython main.py
, the debugging works flawlessly.If I run in a shell manually poetry run ###name### it also works flawlessly.
In principle the debugging with poetry seems to work. It stops at breakpoints and shows error msgs etc. But as mentioned, shortly after that the whole execution stops and I am out of the debugging and the process itself.
Anyone an idea what causes the early exiting?
VSCode: 1.65.2
Poetry (systemwide): 1.1.13
Poetry python:
poetry: 1.1.13
poetry-core: 1.0.8
The text was updated successfully, but these errors were encountered: