前提:专业版pycharm
1.Tools----Deployment----Configuration----添加sftp
填写服务器ip 用户名 端口号 输入密码 测试连接
添加文件夹映射 mapping 选择本地文件路径和服务器端文件路径
2.设置Python Interpreter
File----Settings----project-----Python Interpreter 添加ssh Interpreter
选择existing server configuration,选择刚刚添加的ssh
Interpreter选择服务器环境(ptah/to/anaconda/envs/bin/.../python3.x)
running code on the remote server (本地路径------服务器上传路径)
Python Interpreter show all编辑,选中刚刚配置的远程环境,选择ssh选项,更改环境名和路径
3.运行
Deployment可选将代码上传至服务器或下载至本地,之后就可将代码放在服务器端运行,在本地进行调试
主要参考这位博主:Pycharm远程连接服务器并运行代码(详细!)_cutefery的博客-CSDN博客_pycharm远程连接服务器跑代码