gpt4 book ai didi

python - 使用 "ptvsd"运行远程调试时出错

转载 作者:行者123 更新时间:2023-12-01 08:56:29 25 4
gpt4 key购买 nike

我已经开始使用 Visual Studio 代码进行远程调试,但无法让它工作。远程和本地开发 PC 都运行 ptvsd 版本 4.1.3。远程机器有脚本:

import ptvsd
ptvsd.enable_attach()

#Enable the below line of code only if you want the application to wait untill the debugger has att$
#ptvsd.wait_for_attach()

import random


guesses_made = 0
name = input('Hello! What is your name?\n')
number = random.randint(1, 20)
print('Well, {0}, I am thinking of a number between 1 and 20.'.format(name))

while guesses_made < 6:
guess = int(input('Take a guess: '))
guesses_made += 1
if guess < number:
print('Your guess is too low.')
if guess > number:
print('Your guess is too high.')
if guess == number:
break
if guess == number:
print('Good job, {0}! You guessed my number in {1} guesses!'.format(name, guesses_made))
else:
print('Nope. The number I was thinking of was {0}'.format(number))

本地计算机是:

import ptvsd
ptvsd.enable_attach(address = ('192.34.98.197',3000))

#Enable the below line of code only if you want the application to wait untill the debugger has attached to it
#ptvsd.wait_for_attach()

import random

guesses_made = 0
name = input('Hello! What is your name?\n')
number = random.randint(1, 20)
print('Well, {0}, I am thinking of a number between 1 and 20.'.format(name))

while guesses_made < 6:
guess = int(input('Take a guess: '))
guesses_made += 1
if guess < number:
print('Your guess is too low.')
if guess > number:
print('Your guess is too high.')
if guess == number:
break
if guess == number:
print('Good job, {0}! You guessed my number in {1} guesses!'.format(name, guesses_made))
else:
print('Nope. The number I was thinking of was {0}'.format(number))

我已将条目添加到 launch.json 中:

{
"name": "Attach (Remote Debug)",
"type": "python",
"request": "attach",
"localRoot": "${workspaceRoot}",
"remoteRoot": "/home/pi/testdebug/",
"port": 3000,
"secret": "my_secret",
"host":"localhost"
},

这是我收到的错误:

> PS C:\IOT\Github\RaspberryPi\test_remote_debug> python
> .\test_remote_debug.py Traceback (most recent call last): File
> ".\test_remote_debug.py", line 2, in <module>
> ptvsd.enable_attach(address = ('192.34.98.197',3000)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\attach_server.py", line 72,
> in enable_attach
> redirect_output=redirect_output, File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 85, in
> enable_attach
> suspend=False) File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1313, in settrace
> stop_at_frame, File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1362, in _locked_settrace
> debugger.connect(host, port) # Note: connect can raise error. File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 355, in connect
> s = start_client(host, port) File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\pydevd_hooks.py", line 85,
> in <lambda>
> _start_client = (lambda h, p: start_client(daemon, h, p)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 72, in
> <lambda>
> start_client=(lambda daemon, h, port: start_daemon()), File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 64, in
> start_daemon
> _, next_session = daemon.start_server(addr=(host, port)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\daemon.py", line 157, in
> start_server
> self._server = create_server(addr.host, addr.port) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\socket.py", line 77, in
> create_server
> server.bind((host, port)) OSError: [WinError 10049] The requested address is not valid in its context PS
> C:\IOT\Github\RaspberryPi\test_remote_debug> python
> .\test_remote_debug.py Traceback (most recent call last): File
> ".\test_remote_debug.py", line 2, in <module>
> ptvsd.enable_attach(address = ('192.34.98.197',3000)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\attach_server.py", line 72,
> in enable_attach
> redirect_output=redirect_output, File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 85, in
> enable_attach
> suspend=False) File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1313, in settrace
> stop_at_frame, File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1362, in _locked_settrace
> debugger.connect(host, port) # Note: connect can raise error. File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 355, in connect
> s = start_client(host, port) File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\pydevd_hooks.py", line 85,
> in <lambda>
> _start_client = (lambda h, p: start_client(daemon, h, p)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 72, in
> <lambda>
> start_client=(lambda daemon, h, port: start_daemon()), File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 64, in
> start_daemon
> _, next_session = daemon.start_server(addr=(host, port)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\daemon.py", line 157, in
> start_server
> self._server = create_server(addr.host, addr.port) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\socket.py", line 77, in
> create_server
> server.bind((host, port)) OSError: [WinError 10049] The requested address is not valid in its context

如果有人有任何想法如何纠正此问题,请告诉我。

最佳答案

您的 launch.json 已过时,因为它是为旧调试器配置的。请参阅https://code.visualstudio.com/docs/python/debugging#_remote-debugging了解最新说明(例如 localRootremoteRoote 应位于 pathMappings 下)。

关于python - 使用 "ptvsd"运行远程调试时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52743265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com