> ## Documentation Index
> Fetch the complete documentation index at: https://docs.autodl.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PyCharm远程开发

> [!WARNING]
>
> 警告：如果使用PyCharm直接执行或开终端执行训练程序，请在调试完成后最后通过screen/tmux工具开守护进程（参考文档：[守护进程](https://docs.autodl.com/instance/execution/daemon.md)），确保程序不受SSH连接中断影响程序执行！

## 远程项目开发

官方文档：[请戳](https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html)

AutoDL使用方法：

**Step1**：确认您安装的PyCharm是社区版还是专业版，只有**专业版**才支持远程开发功能。

**Step2**：开机实例

复制自己实例的SSH指令，比如：`ssh -p 38076 root@region-1.autodl.com `

> [!NOTE]
>
> 在`ssh -p 38076 root@region-1.autodl.com`命令中， 各个参数的含义为：
>
> 用户名：root
>
> HOST： region-1.autodl.com
>
> 端口号：38076

**Step3**：配置PyCharm

\[File] -> \[Settings]，打开以下设置弹窗，搜索interpreter找到\[Python interpreter]设置项

![image-20211015161809169](https://mintcdn.com/yogacom/WVwqZdu2fSQRLCml/images/best_practices/remote/pycharm/image-20211015161809169.png?fit=max\&auto=format\&n=WVwqZdu2fSQRLCml\&q=85\&s=05995059b5969a5e410dd68b1120a806)

点击Add Interpreter，选择On SSH并点击 (PyCharm社区版本无该选项)

![image-20221227171317182](https://mintcdn.com/yogacom/WVwqZdu2fSQRLCml/images/best_practices/remote/pycharm/image-20221227171317182.png?fit=max\&auto=format\&n=WVwqZdu2fSQRLCml\&q=85\&s=0c0d6dfd728d8b0edafdb1c3dbb952b4)

将实例SSH指令中的Host、Port与Username进行匹配和填写（Username均为root，Host和Port查看自己实例的SSH指令)

![image-20221227171500338](https://mintcdn.com/yogacom/WVwqZdu2fSQRLCml/images/best_practices/remote/pycharm/image-20221227171500338.png?fit=max\&auto=format\&n=WVwqZdu2fSQRLCml\&q=85\&s=5feb4b4442d4e67d6162c65d5b0b4b6d)

下一步：输入SSH的密码

![image-20221227171552220](https://mintcdn.com/yogacom/WVwqZdu2fSQRLCml/images/best_practices/remote/pycharm/image-20221227171552220.png?fit=max\&auto=format\&n=WVwqZdu2fSQRLCml\&q=85\&s=8e7560f1f622b124fbb126ffb7ff2605)

继续下一步，直到看到下面的弹窗。选择System Interpreter，配置远程Python解释器地址为`/root/miniconda3/bin/python`（如果您在miniconda中安装了其他的虚拟环境，那么虚拟环境的python解释器路径在/root/miniconda3/envs/{对应的虚拟环境名称}/bin/python）

配置同步目录，意思是本地项目和远程实例中的哪个目录进行关联，这里设置为实例的数据盘子目录：`/root/autodl-tmp/project/` （不建议使用默认的/tmp目录）

![image-20221227171704791](https://mintcdn.com/yogacom/WVwqZdu2fSQRLCml/images/best_practices/remote/pycharm/image-20221227171704791.png?fit=max\&auto=format\&n=WVwqZdu2fSQRLCml\&q=85\&s=a38ba85a02dd1153def25bdf83de9bb5)

点击创建，如果配置均无误PyCharm会有小会配置过程，完成后即可远程开发。

如果您在运行时找不到Python文件，可能是没有自动同步代码，那么可以选择手动同步：

![image-20220420144611252](https://mintcdn.com/yogacom/WVwqZdu2fSQRLCml/images/best_practices/remote/pycharm/image-20220420144611252.png?fit=max\&auto=format\&n=WVwqZdu2fSQRLCml\&q=85\&s=73fa18a8834354ed840a6c5fdb00859c)

## 打开远程终端

配置好PyCharm远程开发后，可以在PyCharm的终端中下拉找到远程服务器打开远程终端：

![image-20221227172622410](https://mintcdn.com/yogacom/WVwqZdu2fSQRLCml/images/best_practices/remote/pycharm/image-20221227172622410.png?fit=max\&auto=format\&n=WVwqZdu2fSQRLCml\&q=85\&s=9bc768fa7074e22cc89d0d78541e9816)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.