1、准备工作: 

固定centos的IP,这里我的固定IP为 192.168.254.128
centos中安装ssh。(这里我采用的是ssh的远程连接)
centos中Python环境已安装

2、打开Pycharm,File—>Settings—>Project—>Project Interpreter 选择Add Remote,如下图所示

python远程调用 python远程调用centos命令_python脚本

3、选择SSH Credentials,填写相关参数

python远程调用 python远程调用centos命令_centos_02

注意Linux下的Python所在路径。
这个时候我们已经可以连接到Linux下的Python环境了,调用函数时候会给出相应提示,但仍然无法运行。原因是连接到环境,但我们写的python脚本是在windows下的,Linux下的Python无法访问windows下的python脚本。这时候,如果我们想直接在当前Pycharm下运行python脚本,需要将脚本上传到Linux下。

4、定义deployment settings
File -> Settings -> Build, Execution, Deployment -> Deployment

python远程调用 python远程调用centos命令_Python_03

点击绿色+号,选择SFTP

python远程调用 python远程调用centos命令_Python_04

点击OK,尝试Test SFTP connections。如果给出Successfully connected to ip 即成功。

python远程调用 python远程调用centos命令_python脚本_05

python远程调用 python远程调用centos命令_Python_06

填写相关参数,其中 Root path,是python脚本上传到Linux下的路径。

5、部署代码
选择 Tools -> Deployment -> Upload to {deployment settings name}
Upload process will be started in background. Wait for upload to complete.
打开远程视图,可以看到test.py被上传到Linux下的/tmp/python/文件夹中

python远程调用 python远程调用centos命令_python脚本_07

python远程调用 python远程调用centos命令_python脚本_08

6、运行程序,可以看到ssh调用python

python远程调用 python远程调用centos命令_centos_09