PyCharm Notes | PyCharm 使用笔记(远程访问服务器code配置指南)

本文详细介绍了如何使用PyCharm专业版进行远程代码管理和运行。首先,需理解Interpreter和Deployment概念,前者用于设置服务器解释器,后者实现代码的拉取和推送。通过配置项目解释器和部署路径,实现本地与远程服务器的代码同步。

PyCharm is a strong IDE for python programmer. Not only because it has a similar face with VS or some other IDEs, but also it provides a convenient way to remote manage codes. 

But... how to configure it to achieve this is a headache problem. Here I saved a good guidebook.

 

0. A professional version must be needed.

Community version PyCharm has no remote management function. Luckily, I am a student yet so I can use my edu.cn email address to use the professional version for free.

 

1. Some explicit concepts should be understood.

Here are two concepts may help you have an overall view, Interpreter and Deployment. 

An interpreter is used to run python code. Obviously, you should use your server interpreter to do this instead of running on your local computer. So the first thing you have to do is setting interpreter of PyCharm.

And what makes PyCharm so charming is exactly Deployment. Actually, it is a GitHub-like thing. With it, you can pull code from the server and push edited version back. What you need to do is tell Deployment where are your local codes and remote codes. Yes, just two paths.

 

2. Now we can do it.

(1) Create a new project with PyCharm. Your local codes will be saved in this project.

(2) Interpreter Configuration: Open the new project in PyCharm. Click File -> Settings -> Project: xxx -> Project Interpreter. Now you can find the project interpreter. Click the gear-shaped button, choose to add. Here we should add an SSH interpreter. Input your Host address and username. The things behind are too simple to descript here. 

(If you use Anaconda rather than system interpreter, you can refer to 3(1) below.)

(3) Deployment Configuration: Click Tools -> Deployment -> Configuration. Now you can configure Deployment. Here are three tabs named Connection, Mappings and Excluded Paths. The connection is some information to link your server. And mapping is a corresponding relationship between a local project path with the server project path. Just two root directories' paths. 

 

3. More tricks.

(0) A virtual environment is better. You can use Anaconda to create a virtual environment on the server, then link it in the PyCharm Interpreter. The system interpreter path is /usr/bin/python, but the Anaconda interpreter path is anaconda3/envs/{ENV_NAME}/bin/python.

(1) In the terminal tab of PyCharm, you can use SSH command to log in your server.

(2) Maybe you cannot run via clicking the green triangle button. You should use Run in the menu bar. 

(3) If some problems happened when you are running codes, it may because your server interpreter environment is wrong configuring. Make sure you can run codes correctly on your server before running it in the PyCharm.

 

Reference:

http://www.xzhewei.com/Tutorial-%E6%95%99%E7%A8%8B/remote-debug/

https://www.xncoding.com/2016/05/26/python/pycharm-remote.html

转载于:https://www.cnblogs.com/hizhaolei/p/10001459.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值