Remote Deployment using Pycharm

Have you ever wanted to develop a Python or Web application for Linux from your laptop running Windows 7 or MAC OS X? Do you want to run your code that  will be published to whole world but afraid from the dependencies mismatch between your laptop and   production server?

Guess what: all of this is possible with the remote development features already available in PyCharm.

clip_image001

Here’s the deal:

1- You will connect to remote server (production or staging)

2-Once connected, Your local files will be uploaded over SFTP to remote server

3-If your run your code from your local laptop, The Pycharm will use the remote dependencies and remote interpreter to run it not the local (which will eliminate any dependencies mismatch)

Tools Used

1-Pycharm (Popular Python IDE) v4.5 or higher

2-Remote Server (Centos/RHEL/Debian/Ubuntu)

3-Network between them

 

How to do it

[1]Open Pycharm and from Tools > Deployment > configuration

clip_image002

[2] Provide needed SSH credentials (root/password/IP address) and choose SFTP

clip_image003

if you will connect to Debian/Ubuntu, it may throw the following error “Invalid descendant file name “\””

clip_image004

Click on Advanced and choose Compatibility mode

clip_image005

Then Ignore this error and continue to add

[3] Select the mapping

clip_image006

-Here we will map between the local and remote location. in other word any file found in Local Path(Windows Machine) will be automatically uploaded to Deployment Path (Linux Machine)

[4]Modify the interpreter location (Use the remote interpreter to run your project) from File>Settings>Project Interpreter>Add Remote

clip_image007

[5]Sometimes the server has multiple interpreters and versions (Python2.7, Python2.6 and so on) so you can choose which python interpreter (2.6 or 2.7) needed to be synced by providing it in Python Interpreter Path. to know which python path in linux, you can use “#which python” command

clip_image008

[6] Press Ok and Sync will be in progress. Basically Pycharm is installing some files (PytCharm helpers) on remote machine to allow him to run your code in far-end deployment

clip_image009

clip_image010

[7]-Click on waiting icon to see the currently uploaded, downloaded files from your Deployment server

clip_image011

clip_image012

 

[8]- Voilà! a new Interpreter is shown in Project Interpreter that use the remote serverclip_image013

Files uploaded on the server

clip_image014

[9]-Now Create a new Interpreter Configuration that point to remote file and remote python interpreter

clip_image015

[10]-If you click Run then a  command will be sent to remote server using SSH to run your script and print the output  (note the use of python 2.6 to run)

clip_image016

[10]-Finally, make sure you choose Automatic upload for your files so any modification will be uploaded automatically clip_image017

Notes

[1]-if you’ve multiple Deployment server, You can choose which one will be the default

clip_image018

[2]-you can enforce sync and choose which server you need this file to sync to (Only one destination is allowed)

clip_image019

clip_image020

[3]-However you can upload the file to another Deployment server

clip_image021

 

[4]-You can explore the contents of remote server just like the WinSCP

clip_image022

 

Wrapping Up

Trying to replicate the production environment to your development machine has been always a problem in DevOps world. A projects like Vagrant , Docker and Puppet launched in order to solve these problems. However it will take some time till being matured  and familiar for everyone . The above method is trying to solve this problem and run your code using the same dependencies in production network to eliminate the #1 reason on the below comic 😀

 

Advertisements

3 thoughts on “Remote Deployment using Pycharm

Share you opinion to benefit others :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s