Pydev-Pfadzuordnung mit virtueller UmgebungPython

Python-Programme
Anonymous
 Pydev-Pfadzuordnung mit virtueller Umgebung

Post by Anonymous »

Siehe auch Beim Versuch, a. aus der Ferne zu debuggen Python-Projekt, ich stoße auf eine Situation, die ich lösen möchte.
Meine IDE ist Eclipse 2025-12 auf Mac OS mit LiClipse und pydev 13.0.1.202502081502.
Remote-Debugging funktioniert gut, wenn mein Zielcomputer kein Venv verwendet und sogar mit Venv
wenn ich mit der Pfadzuordnung herumspiele, z. B. mit einem Ziel von Ubuntu 22 und Python 3.10/3.11
Die Dinge werden für mich unkontrollierbar, wenn das Ziel Ubuntu 24 LTS ist. Ich habe Python 3.12, was mich zwingt, venv zu verwenden.
Wenn ich das mache, sind die PYTHONPATH-Einträge nicht mehr einfach.
Ich versuche, dies mit python -e zu mildern installiert.
Ich starte dann den Debugger mit einem Remote-Tunnel

Code: Select all

ssh -R 5678:localhost:5678 ubuntu ". .profile;bin/debug_cms"
unter Verwendung des Startup-Codes von
https://github.com/WolfgangFahl/pybasem ... ase_cmd.py
und der Zuordnung

Code: Select all

  --debugRemotePath /Users/wf/py-workspace/,/Users/wf/Library/Python/3.12/lib/python/site-packages/basemkit/ \
--debugLocalPath /home/wf/source/python/,/home/wf/source/python/pybasemkit
Am Ende habe ich

Code: Select all

pydev debugger: Trying to add breakpoint to file that does not exist: /Users/wf/Library/Python/3.12/lib/python/site-packages/basemkit/base_cmd.py (will have no effect).
Die Meldung ist ziemlich irreführend, die Datei existiert tatsächlich auf der IDE-Seite.
Wenn ich die Pfadzuordnung auf die einfachere ändere

Code: Select all

 --debugRemotePath /Users/wf/py-workspace/ \
--debugLocalPath /home/wf/source/python
Am Ende habe ich Folgendes:

Code: Select all

➜ starting python -X frozen_modules=off -m frontend.cmsmain --serve --host 0.0.0.0
Local=qn.bitplan.com
Remote=127.0.0.1
DEBUG: I am running in: /home/wf/source/python/pyWikiCMS
DEBUG: This file is at: /home/wf/source/python/pybasemkit/basemkit/base_cmd.py
DEBUG PATH MAP: Remote (IDE)='/Users/wf/py-workspace/'  Local='/home/wf/source/python' ✅
1.07s - pydev debugger: unable to find translation for: "/Users/wf/Library/Python/3.12/lib/python/site-packages/basemkit/base_cmd.py" in ["/Users/wf/py-workspace/", "/Users/wf/py-workspace"] (please revise your path mappings).
was auch eine seltsame Meldung ist, wenn man bedenkt, was in der Debug-Ausgabe steht.
die Json-basierte Zuordnung

Code: Select all

[
{
"localRoot": "...",
"remoteRoot": "..."
}
]
scheint kontraproduktiv zu sein, da es sich nicht an verschiedene Zielmaschinen anpassen kann und andere Pfadzuordnungen zu beeinträchtigen scheint
Leider verfolgt mich das seit 2011 https://stackoverflow.com/a/41765551/1497139
und selbst 14 Jahre später bin ich immer noch verwirrt und verstehe nicht, wie die Zuordnung richtig funktionieren soll. Ich habe es einige Jahre lang laufen lassen und war glücklich, die Komplexität zu verbergen, und jetzt ist es wieder in vollem Gange.
Was kann getan werden, um venv-basierte Projekte korrekt abzubilden?
Zum Debuggen verwende ich

Code: Select all

export PYDEVD_DEBUG=1
export DEBUG_PYDEVD_PATHS_TRANSLATION=1
export PYDEVD_LOG_DIR=/tmp/pydevd
und versuchen Sie, den Quellcode unter base_cmd
zu verstehen

Code: Select all

if args.debugServer:
import pydevd
import pydevd_file_utils

remote_path = args.debugRemotePath
local_path = args.debugLocalPath

# note the complexity of https://stackoverflow.com/a/41765551/1497139
# discussed in 2011
if remote_path and local_path:
remotes = [r.strip() for r in remote_path.split(",")]
locals_ = [l.strip() for l in local_path.split(",")]
if len(remotes) != len(locals_):
raise ValueError("debugRemotePath and debugLocalPath must have the same number of entries")
mappings = list(zip(remotes, locals_))
if args.debug:
fqdn = socket.getfqdn()
print(f"Local={fqdn}",file=sys.stderr)
print(f"Remote={args.debugServer}",file=sys.stderr)
print(f"DEBUG: I am running in: {os.getcwd()}",file=sys.stderr)
print(f"DEBUG: This file is at: {os.path.abspath(__file__)}",file=sys.stderr)
for r, l in mappings:
marker="✅" if os.path.exists(l) else "❌"
print(f"DEBUG PATH MAP: Remote (IDE)='{r}'  Local='{l}' {marker}", file=sys.stderr)
# https://github.com/fabioz/PyDev.Debugger/blob/main/pydevd_file_utils.py
pydevd_file_utils.setup_client_server_paths(mappings)

pydevd.settrace(
args.debugServer,
port=args.debugPort,
stdoutToServer=True,
stderrToServer=True,
suspend=True
)
print("Remote debugger attached.")

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post