Pycharm应该可以算是最强大的python IDE了,但与它强大的本地开发能力相比,它的远程开发能力一般,特别是以前,它的远程开发实际基于SFTP, 远程目录和本地目录不断进行同步,这种方式使用起来麻烦,严格来说算不上真的远程开发。后来Jetbrains又搞起了Projector,顾名思义就是把远程IDE投射到本地,再后来,Projector停止开发了,转而开发Gateway,这才有点向VSCode的远程开发看齐的意思了。
1. SFTP方式
- 在 ”工具—部署“中添加远程服务器的地址,映射—部署路径直接选择“/”
- 添加 ssh 远程解释器,注意同步文件夹的设置一定要正确
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2Fc47d11c8-96ac-4595-a0b5-54da4d7e9b5c%2FUntitled.png?table=block&id=36e938ca-22a5-43b0-8e65-1a1fdb07f39c&t=36e938ca-22a5-43b0-8e65-1a1fdb07f39c&width=680&cache=v2)
要对该文件进行修改时,注意一定要先Download下来。Remote Host里的文件,当你执行非打开操作的时候,所指代的都是服务器上的文件,比如你可以从这里选择下载,进行比对操作等。但是当你从Remote Host双击打开文件时,这时打开的就不是服务器上的,而是一个镜像文件。所以如果直接修改从Remote Host双击打开的文件,修改是无效的。一定要先下载下来,进行修改,然后再上传过去。随后进行在
Tools/Deployment/Configuration
中进行远程连接的配置(可以设置自动上传)。![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2F1f487c67-2d4a-4ce7-bc57-8e1ffa952903%2FUntitled.png?table=block&id=743c1e51-c1b4-4d8b-bca2-b2bb1082af9e&t=743c1e51-c1b4-4d8b-bca2-b2bb1082af9e&width=1820&cache=v2)
2. Projector方式
这一方式是基于RDP(remote display protocol)协议,将IDE运行的画面通过web的形式显式,比较类似于VSCode的web方案CodeServer。
3. Gateway方式
Gateway是Jetbrains最新的远程方案,目标是与VSCode看齐。在建立连接后能够直接在本地修改、运行服务器的代码文件。
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2Ff7959cb8-bfc1-4959-91c4-a0598cc234c9%2FUntitled.png?table=block&id=776a8cee-1c3f-4bd8-9b4d-69398df0a499&t=776a8cee-1c3f-4bd8-9b4d-69398df0a499&width=1631&cache=v2)
操作流程
- 在文件中打开远程开发
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2F51fdf16d-fbec-4704-9f54-bb4523d72f1d%2FUntitled.png?table=block&id=590889e6-daf7-486c-a3a2-eb196fc40de5&t=590889e6-daf7-486c-a3a2-eb196fc40de5&width=338&cache=v2)
- 选择SSH新建连接
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2F279e673e-7e5b-4e3d-b627-e5cb258fbcd9%2FUntitled.png?table=block&id=e23dba46-a5db-4b54-844d-52d995af851e&t=e23dba46-a5db-4b54-844d-52d995af851e&width=528&cache=v2)
- 输入需要连接的服务器IP地址和你的用户名
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2F501a2974-2fd7-4134-991c-1ebca9238386%2FUntitled.png?table=block&id=2f174f5c-63ec-4516-931f-5b42ecf4bcf3&t=2f174f5c-63ec-4516-931f-5b42ecf4bcf3&width=576&cache=v2)
- 输入用户密码,建立连接
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2F16d0e18e-afb0-46a9-bcb4-b48ab5ad0e66%2FUntitled.png?table=block&id=d22aa82b-4911-4fd9-a881-5a384d00a026&t=d22aa82b-4911-4fd9-a881-5a384d00a026&width=576&cache=v2)
- 安装Gateway,选择在服务器上安装的路径以及项目路径
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2F1a0084f1-5689-4a1b-b286-0a8c1e7939eb%2FUntitled.png?table=block&id=657e74de-3974-40d1-bffc-234d828d89bd&t=657e74de-3974-40d1-bffc-234d828d89bd&width=576&cache=v2)
直接从网上下载pycharm到服务器很容易出bug,可以选择直接在jetbrains官网下载linux版本的pycharm文件,然后选择“上传安装程序文件”,即可
- 漫长的等待之后,进入到gateway中,此时还没有配置解释器。
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2Fd50f83a0-c210-4711-a311-a110dcd34121%2FUntitled.png?table=block&id=9e282edb-ea89-4a27-810a-6a35d47e2240&t=9e282edb-ea89-4a27-810a-6a35d47e2240&width=576&cache=v2)
此时会显示没有conda可执行文件。
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2F68e4818e-7961-4b79-9571-7af5ea2683b3%2FUntitled.png?table=block&id=a5ff22b7-5813-43a4-8e5e-06d598a5ac7d&t=a5ff22b7-5813-43a4-8e5e-06d598a5ac7d&width=576&cache=v2)
- 找到
anaconda3/bin
目录下的conda
文件,双击。
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2F860fd501-d386-4bb5-ae46-4c15a5d7b389%2FUntitled.png?table=block&id=3bb607f7-b61d-4eff-8629-4de02edc8761&t=3bb607f7-b61d-4eff-8629-4de02edc8761&width=576&cache=v2)
- 选择服务器上创建好的环境DL
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fd44e9d98-a87c-43f5-892e-ed2ad4c03b59%2F1148292b-a1d6-4e81-bb5a-6b735bd79f32%2FUntitled.png?table=block&id=60028e34-95a0-4596-905e-c08ac4ddc5f9&t=60028e34-95a0-4596-905e-c08ac4ddc5f9&width=576&cache=v2)
- 🆗!