Remote launch in PyCharm Community Edition
PyCharm is the most convenient, in my opinion, IDE for Python from the authors of the magnificent PhpStorm. Unlike the development tool in PHP, it has a free version with a few truncated functionality, in particular without a smart module for launching and debugging scripts on a remote server. Nevertheless, standard features are enough for creating desktop windows-applications, and for scripting, and for server code.
This feature became critical at the moment when I wanted to write scripts on a PC and get the result of their execution on the Raspberry Pi without copying and starting manually. Next is my recipe for Windows 8.1 (launch only).
Yes, let's go along a difficult path and use a machine running Windows as a workstation. It would be easier to do this on Linux, but at the same time I decided to look at the possibilities of the new Windows PowerShell for me instead of bash. Surprisingly, he did it. You can also use cmd.exe and bat files.
So, hardware - Raspberry Pi of any model with raspbian on board, LAN access and working ssh. A PC with windows is connected to the same network, PyCharm and Python are already installed on it (at the time of writing, the current version in the Raspbian repositories is 3.2, it is better to install the same).
The Microsoft OS does not have regular ssh clients, so we put something convenient like Xshell on it: www.netsarang.com/download/down_xsh.html . I also needed putty command line utilities: pscp and plink: www.chiark.greenend.org.uk/~sgtatham/putty/download.html . By the way, pytty itself is also quite convenient.
I will execute scripts as root. You can’t do that.
Turn on the client (Xshell), connect to raspberry, set
First, create a fake interpreter. Run Windows PowerShell as administrator, create a daddy.
In order not to lose or litter in PATH, drop pscp and plink here:
PyCharm only accepts files with the name python.exe as an interpreter executable, so let's do such a bad thing:
You may have to disable script signature verification:
Create a script file to upload the project to the server, for example, this (let deploy.ps1 be called):
Where 192.168.1.230 is the address of the remote server, root and passw0rd are the login and password. Hardcode is enough for once.
This version takes the address of the local folder and the name of the folder that you want to create on the server, and simply copies all the contents from the first to the second. For projects of more than a hundred kilobytes, it is worth optimizing this place.
Create a file for transferring and running code on the server (let python.ps1). In the simplest case, this:
Where testProject is the name of the future project.
Let's make the shell interpreter run instead of the python interpreter.
After creating the project, go to File-> Settings or Ctrl-Alt-S. In the project tab - Project Interpreter. Click Add Local:

Add:

IDE swears, but adds to the list. Click "More .." and rename it to wrapper:

It is better to return Project Interpreter back to version 3.2 (I have 3.4), otherwise the tips and auto-completion will fall off.
That's all, open Run-> Edit Configurations startup configurations. And we add two config files:
- Normal for local debugging:

- And our monster for remote launch:

Where we choose our wrapper as an interpreter and set a constant parameter - the path to the python.ps1 file. Thus, in fact, powershell will be called, which will execute the python.ps1 script passed to it with the transfer of all subsequent parameters.
Now it’s already possible to write Hello World and execute it on the target machine, but in this form we can only test projects from a single file. To upload the entire project to the server, add an external tool here.

All. Now, with the remote configuration selected, after clicking the Run button, the project will be poured onto the remote server, where the main.py script will be run, whose stdout will be displayed back to the pycharm console.
For some flexibility and ease of configuration, you can add the generation of the python.ps1 script using the project name, and transfer the data about the remote host to one place
deploy.ps1
Now, to configure for a new server, it will be necessary to change only three lines, and when creating a new project, add the remote configuration to it.
This feature became critical at the moment when I wanted to write scripts on a PC and get the result of their execution on the Raspberry Pi without copying and starting manually. Next is my recipe for Windows 8.1 (launch only).
Yes, let's go along a difficult path and use a machine running Windows as a workstation. It would be easier to do this on Linux, but at the same time I decided to look at the possibilities of the new Windows PowerShell for me instead of bash. Surprisingly, he did it. You can also use cmd.exe and bat files.
So, hardware - Raspberry Pi of any model with raspbian on board, LAN access and working ssh. A PC with windows is connected to the same network, PyCharm and Python are already installed on it (at the time of writing, the current version in the Raspbian repositories is 3.2, it is better to install the same).
Communications
The Microsoft OS does not have regular ssh clients, so we put something convenient like Xshell on it: www.netsarang.com/download/down_xsh.html . I also needed putty command line utilities: pscp and plink: www.chiark.greenend.org.uk/~sgtatham/putty/download.html . By the way, pytty itself is also quite convenient.
Python on the board
I will execute scripts as root. You can’t do that.
Turn on the client (Xshell), connect to raspberry, set
apt-get install python3
"Fake" interpreter
First, create a fake interpreter. Run Windows PowerShell as administrator, create a daddy.
cd \
mkdir PythonWrapper
cd PythonWrapper
In order not to lose or litter in PATH, drop pscp and plink here:
cp ~\Downloads\plink.exe .
cp ~\Downloads\pscp.exe .
PyCharm only accepts files with the name python.exe as an interpreter executable, so let's do such a bad thing:
PS C:\PythonWrapper> cmd.exe /c mklink python.exe C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
символическая ссылка создана для python.exe <<===>> C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
You may have to disable script signature verification:
Set-ExecutionPolicy Unrestricted
Create a script file to upload the project to the server, for example, this (let deploy.ps1 be called):
C:\PythonWrapper\plink -ssh root@192.168.1.230 -pw passw0rd 'rm -rf '$args[1]';mkdir -p '$args[1]
$dpath = 'root@192.168.1.230:~/' + $args[1] + '/'
C:\PythonWrapper\pscp -r -scp -pw passw0rd $args[0] $dpath
Where 192.168.1.230 is the address of the remote server, root and passw0rd are the login and password. Hardcode is enough for once.
This version takes the address of the local folder and the name of the folder that you want to create on the server, and simply copies all the contents from the first to the second. For projects of more than a hundred kilobytes, it is worth optimizing this place.
Create a file for transferring and running code on the server (let python.ps1). In the simplest case, this:
cat $args[0] | C:\PythonWrapper\plink -ssh root@192.168.1.230 -pw passw0rd 'cd testProject/testProject;python3 -'
Where testProject is the name of the future project.
IDE setup
Let's make the shell interpreter run instead of the python interpreter.
After creating the project, go to File-> Settings or Ctrl-Alt-S. In the project tab - Project Interpreter. Click Add Local:

Add:

IDE swears, but adds to the list. Click "More .." and rename it to wrapper:

It is better to return Project Interpreter back to version 3.2 (I have 3.4), otherwise the tips and auto-completion will fall off.
That's all, open Run-> Edit Configurations startup configurations. And we add two config files:
- Normal for local debugging:

- And our monster for remote launch:

Where we choose our wrapper as an interpreter and set a constant parameter - the path to the python.ps1 file. Thus, in fact, powershell will be called, which will execute the python.ps1 script passed to it with the transfer of all subsequent parameters.
Now it’s already possible to write Hello World and execute it on the target machine, but in this form we can only test projects from a single file. To upload the entire project to the server, add an external tool here.

All. Now, with the remote configuration selected, after clicking the Run button, the project will be poured onto the remote server, where the main.py script will be run, whose stdout will be displayed back to the pycharm console.
Improvement
For some flexibility and ease of configuration, you can add the generation of the python.ps1 script using the project name, and transfer the data about the remote host to one place
deploy.ps1
$dhost = '192.168.1.230'
$password = 'passw0rd'
$login = 'root'
"cat `$args[0] | C:\PythonWrapper\plink -ssh $($login)@$($dhost) -pw $($password) 'cd {0}/{0};python3 -'" -f $args[1]> .\python.ps1
$duser = $login + '@' + $dhost
.\plink -ssh $duser -pw $password 'rm -rf '$args[1]';mkdir -p '$args[1]
$dpath = $duser + ':~/' + $args[1] + '/'
.\pscp -r -scp -pw $password $args[0] $dpath
Now, to configure for a new server, it will be necessary to change only three lines, and when creating a new project, add the remote configuration to it.