pycharm配置远程解释器

1 说明

环境

  • pycharm 2017(pycharm 2019 在目录结构上有调整,可自行摸索)

作用

  • 调试。在本地编写的python代码终究还是要部署到服务器的,能直接在服务器环境调试当然最好。
  • 内存。做数据分析的时候会需要处理大量的数据,有时候本地内存根本吃不消,而服务器环境下内存充裕。
  • 备份。使用远程解释器后,所有本地代码都会同步到远程环境相当于多了一重备份。

2 配置远程项目

选择 tools \rightarrow deployment \rightarrow configuration 。添加远程连接
pycharm配置远程解释器
在connection面板配置远程环境,Root path设置为远程环境中为项目设定的根目录(与项目同名的空目录)。
pycharm配置远程解释器
在mappings面板配置本地项目到远程环境的映射,这里直接填‘/’。
pycharm配置远程解释器
点击OK完成配置

3 配置远程解释器

选择 file \rightarrow settings \rightarrow project \rightarrowProject interperter \rightarrow Add Remote
pycharm配置远程解释器
选择远程环境和解释器路径。其中python interpreter 应该选择远程环境中python解释器的路径。如果是使用的anaconda就应该是anaconda的bin目录下对应的python解释器,如果使用virturenv创建的python虚拟环境,则应该是对应虚拟环境下的python解释器路径。
pycharm配置远程解释器

4 远程环境变量

远程用户下设置的环境变量不会被pycharm读取,这时候必须要手动配置。否则,比如oracle这种需要配置客户端环境变量的就无法连接了。

4.1 Console 环境变量

选择 file \rightarrow settings \rightarrow project \rightarrow build execution deployment \rightarrow Console \rightarrow python console

点击environment variables 选择框填写环境变量。注意此时environment variables下面的python interpreter就应该已经是对应的远程解释器地址了。
pycharm配置远程解释器

4.2 Run 环境变量

选择 Run \rightarrow edit configurations
配置环境变量,界面类似配置Console环境变量的界面。

5 查看远程工程

选择 tools \rightarrow deployment \rightarrow remote host。连通的远程项目的导航栏会显示为绿色。
pycharm配置远程解释器