需要pycharm专业版才可以远程调试

一、启动docker时加port映射

如:-p 2892:22,这里把服务器的22端口号映射到外面2892;

二、设置ssh

1. 安装ssh

sudo apt update
sudo apt install openssh-server

2. 设置ssh

打开配置文件:

sudo vim /etc/ssh/sshd_config

(1)取消注释

Port 22

(2)修改

#PermitRootLogin prohibit-password

改为:

PermitRootLogin yes

3. 重启服务

service ssh start

4. 设置密码

passwd

三、连接

进入设置步骤:File->settings->Project:XXX->Python Interpreter

Python Interpreter中增加ssh服务,然后设置:

ip:主机ip
端口号:设置的映射端口号,这里是2892
用户名:root(统一)
密码:第4步设置的密码

然后在docker上which python3看python的位置,设置python环境就好了,enjoy~

四、Q&A

  • 问题1

远程Debug时External Libraries没东西

解决方案:
在设置连接服务器时,点击:
在这里插入图片描述
输入你的环境包路径即可:
在这里插入图片描述

  • 问题2

配置环境时报错:/usr/bin/python: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory

解决方案:

which python
ldd /usr/bin/python

find / -name “libpython3.7m.so.1.0” 找到路径:/usr/local/lib/libpython3.7m.so.1.0

/etc/ld.so.conf.d目录,创建文件python3.conf,加入这个库所在的路径/usr/local/lib,再:

ldconfig

更多推荐