只找到了这样一个解决方案: 1. 共享你的项目目录,确保桌面和远程代码完全对等。2. 确保远程机器(或 VM)可以 ping 您安装了 PyCharm 的台式电脑。3. 按照 PyCharm 说明使用其 pydev.egg 进行远程调试。
这不太方便,因为每次要再次调试应用程序时都应该在远程机器或虚拟机上重新启动应用程序。PyCharm 远程调试中还有一个错误:如果您在桌面操作系统中使用西里尔语言环境,您可能会遇到路径映射错误。所以目前我无法让它与断点一起正常工作。
这是我的调试代码:
from os import system as sys_call
import os
import sys
debug_egg_dir = "PyCharm\\debug-eggs\\"
debug_egg_name = "pycharm-debug-py3k.egg"
python_dir = os.path.dirname(sys.executable)
PORT = 15999
def connect(server):
if sys_call("ping -n 1 " + server + ">nul") != 0:
raise ConnectionError("PyCharm Debug Server ({}) is not available".format(server))
try:
sys.path.append(python_dir + "\\" + debug_egg_name)
import pydevd
pydevd.settrace(server, port=PORT, stdoutToServer=True, stderrToServer=True, suspend=False)
except ImportError:
raise FileNotFoundError("Copy file {0}{1} into {2}".format(
debug_egg_dir,
debug_egg_name,
python_dir
))
except Exception as e:
raise e