Develop with local pycharm using the AWS instance interpreter!
When it is extremely difficult to install a specific module, it is very easy to use the AWS AMI or docker container that is already installed. However, I want to code with an IDE such as pycharm, so entering the server and developing with vim is a bit difficult. .. With pycharm, I found a function that allows me to log in to a server with remote and code using the interpreter of that server, so I will try it and write a note.
Click Pycharm Preferences-> Project: hoge-> Project Interpreter and the following screen will appear. If you click on this gear in the upper right, The following window will appear, so press "Add Remote".
When you press Add Remote, the interpreter Configure will appear, so when you press SSH Credentials, the following setting screen will appear.
Specify the following for each here.
--Specify a public IP such as Host: 54.xx.xx.xx --port: Specify the port number for ssh connection --user name: ec2-Specify a ssh connection user such as user --Specify the connection method of Auth type: password or pem --password: Specify the password or the save destination of the pem file --Python interpreter path: Specify the interpreter path.
This is OK. Occasionally, depending on the AMI, the working environment may be built as a root user instead of a general user such as ec2-user, so in this case I will play with sshd_config and the public key.
# sshd_Modify config
vi /etc/ssh/sshd_config
# PermitRootLogin forced-commands-only below.
PermitRootLogin without-password
#Copy of public key
mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys_bak
cp -f /home/ec2-user/.ssh/authorized_keys /root/.ssh/authorized_keys
service sshd reload
I've written so far, but I've noticed that this feature is quite annoying. .. First, it cannot be executed unless the local path exists on the remote side. Perhaps it is correct to use this function by uploading what was written locally to the remote as it is? Then, there are some modules that cannot be imported for some reason. I'm using caffe, but import caffe says it doesn't. There is no pycaffe under anaconda, so I may have to move it under anaconda.
Hmmm, can I use it to create a source with a local IDE that doesn't give an import error and raise it? ?? Wonder. .. It's pretty sad that I can't debug, though. .. .. I will investigate the above problem if there is spare capacity.
I noticed the correspondence between local and remote paths and the auto upload function, so I added it.
1 Click "Edit Configration .." from "RUN" on the upper tab. 2 Click the right side of Path Mapping. 3 Set the local path and Remote path. that's all.
Even if you associate it, the work is local, so you have to upload the changed source to AWS one by one. How to automatically upload the source modified by local pycharm to AWS. 1 In Preferences-> Deployment, press the + button. 2 Select SFTP and specify the global IP Root path = "/" keypair. You can leave Browse files on server as it is. 3 In Preferences-> Deployment-> Options, change Upload changed files automatically ... to Always and specify Override default permissions on files: as any permissions. that's all.
Now you can code locally in pycharm and develop it with immediate reflection on AWS. You can also debug. Great.
An error may occur because there is no path for cuda's lib system. In that case, set the following in Environment Variable in the Configurations of Run.
LD_LIBRARY_PATH /usr/local/cuda/lib64:$LD_LIBRARY_PATH
I don't know exactly, but it seems to cause an error if Xcode cannot be used on the server. Therefore, work is required to complete with local Xcode.
ssh -Y username@ipaddress
With the connection of 2.1, check the contents of DISPLAY with the following command.
echo $DISPLAY
> localhost:10.0
DISPLAY localhost:10.0
Debug with pycharm with 4.1 connection. OK.
If you connect from the local with the following, specify the port to use on the server as 9999, and go to the local browser with localhost: 8888, the access will be port forwarded to 9999 and you can display it. ..
ssh -L 8888:localhost:9999 user@pablic_ip
Recommended Posts