PyCharm remote deployment: user name not being saved - python

Working with Professional edition of PyCharm, I'm trying to configure a server for remote deployment of my project over SFTP with OpenSSH + authentication agent as auth type. I have tried to configure PyCharm in Settings > Build, Execution and Deployment > Add server. However, even though I setup and verify successful configuration by Test SFTP connection button, as soon as I click Apply or OK, the User name becomes blank for some reason. Thereafter, when I try to sync with the remote server, the connection fails.
I've found a possible workaround by changing Host name to user#host form instead, which works, but then I can't use the same server configuration when I try to setup a remote interpreter under Project > Project Interpreter > Add SSH interpreter. (there it shows my host url as ssh://null#host). I'm guessing the null is there because PyCharm is somehow not saving the username. I've tried to edit the .idea/webServers.xml file, but couldn't find appropriate key-value pair to change there for user name to be preserved.

I solved it by changing the standard way to change credentials in Pycharm.
To do this go to Settings/Preferences | Appearance & Behavior | System Settings | Passwords and choose the KeePass option.
That solved the problem for me.
Apparently there are problems storing on native keychain. (I'm on Mint 18.3)

What worked for me was first going to the following tab:
Preferences -> Build, Execution, Deployment -> Deployment [Connection Tab]
and then inserting my in the "User name" blank.
Note: your user name appears in the ip address of you ec2. e.g. username##xxx.amazonaws.com

Related

Jenkins on Windows: UE4 packaging for iOS fails with "Host key verification failed."

I have this Jenkins server running on my Windows machine. What the jobs do is it runs some python code that is also on the same machine, to package .ipa file (for iOS) using UE4 engine and ships it.
Everything works just fine if I run python code locally. But when I run it through Jenkins, it will fail at some point where UE4 is trying to sign the package. This is partial error message I'm getting.
Using remote server 'XXX.YYY.ZZZ.56' on port 22 (user '***********')
[Remote] Using private key at ...\RemoteToolChainPrivate.key
ERROR: Unable to determine home directory for remote user. SSH output:
Host key verification failed.
I think for some reason Jenkins doesn't know where ssh related stuffs are located in windows.
How can I fix this issue?
Assuming you installed Jenkins as a Windows Service, then Jenkins is probably running as another user (not the user you sign in as).
In the Services app, you can change the user the service is running as if necessary. You can find the Services app here:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\services.lnk
See About Services for more info.
That explains why the remote cannot find the home directory (because the remote user has a different name than the service account user) and also why the host key verification failed (since you never accepted the host key as the service account user).

Apache service wont start through windows services

Using Apache2.4
I could able to start the server and listen on port 8080 through powershell or cmd.
I created a windows service using
httpd.exe -k install
and I could see the service installed as Apache2.4.
When I try to start the server through the windows service it fails with below error, whereas I could able to start the apache server from cmd(run perfectly).
Error output here
When this problem appears and but running httpd through cmd works fine, Please see in event viewer to see the detailed error
Run -> eventvwr -> windows -> Application ->
If you can run httpd.exe via command line, but are unable to start it as a service; the problem might be in folder permissions.
(as stated by Pradeep, see:) Run > eventvwr > windows > Application > ...
If the error is:
DocumentRoot must be a directory .
Make sure that all paths with DocumentRoot, you have added in your apache config, can be accessed by the service.
Right click the folder
Select Properties
Go to the "Security" tab
Default values (in my case, windows 10 pro) are:
Authenticated Users
SYSTEM
Administrators (PC-Name\Administrators)
Users (PC-Name\Users
One of the folders in DocumentRoot did not have the above users listed, but only my hotmail account, meaning the system was unable to access the specific folder.

How to use PyCharm with Google compute engine

I have a compute engine instance running on Google cloud platform.
I would like to use the Python interpreter of the compute engine as a remote interpreter with Pycharm. This means that I would be using Pycharm on my local machine and running computations remotely.
Any clue on how to achieve this?
The following requires, as James Hirschhorn pointed out, the Professional verison of PyCharm.
Assign a public IP to the remote machine on GCP.
Run gcloud compute config-ssh to automatically add the VMs of your project to your ~/.ssh/config or manually add the public IP of your VM to it. If you skipped step 1. then you have to run gcloud compute config-ssh every time you re-start the remote VM, because it always gets a new IP assigned. The ~/.ssh/config gets populated with many entries in the following format:
Host the-vm-host-name # use this in PyCharm's Host field
HostName 123.456.789.00 # the VM's IP address
Use the Host name of the remote you want to connect in your Deployment configuration in PyCharm
Add a remote interpreter: select the remote server from the drop-down (the one previously created) and point PyCharm to the executable python of your Python installation.
Done
My understanding is that you need the Pycharm Ultimate Edition to support remote servers. If you have Ultimate, then you can follow these instructions.
It's fairly easy to accomplish.
You need:
PyCharm Pro
Create and format SSH keys
Config your Compute Engine instance with the SSH keys
Configure PyCharm
You can follow this tutorial that I wrote.

How to remote debug in PyCharm

The issue I'm facing right now:
I deploy Python code on a remote host via SSH
the scripts are passed some arguments and must be ran by a specific user
the PyCharm run/debug configuration that I create connects through SSH via a different user (can't connect with the user that actually runs the scripts)
I want to remote debug this code via PyCharm...I managed to do all configuration, I just get permission errors.
Are there any ways on how I can run/debug the scripts as a specific user (like sudo su - user)?
I've read about specifying some Python Interpeter options in PyCharm's remote/debug configuration, but didn't manage to get a working solution.
If you want an easy and more flexible way to get into the PyCharm debugger, rather than necessarily having a one-click "play" button in PyCharm, you can use the debug server functionality. I've used this in situations where running some Python code isn't as simple as running python ....
See the Remote debug with a Python Debug Server docs for more details, but here's a rough summary of how it works:
Upload & install remote debugging helper egg on your server (On OSX, these are found under /Applications/PyCharm.app/Contents/debug-eggs)
Setup remote debug server run configuration: click on the drop-down run configuration menu, select Edit configurations..., hit the + button, choose Python remote debug.
The details entered here (somewhat confusingly) tell the remote server running the Python script how to connect to your laptop's PyCharm instance.
set Local host name to your laptop's IP address
set port to any free port that you can use on your laptop (e.g. 8888)
Now follow the remaining instructions in that dialog box: copy-paste the import and pydevd.settrace(...) statements into your code, specifically where you want your code to "hit a breakpoint". This is basically the PyCharm equivalent of import pdb; pdb.set_trace(). Make sure the changed code is sync'ed to your server.
Hit the bug button (next to play; this starts the PyCharm debug server), and run your Python script just like you'd normally do, under whatever user, environment etc. When the breakpoint is hit, PyCharm should drop into debug mode.
I have this (finally) working with ssh RemoteForward open, like so:
ssh -R 5678:localhost:5678 user#<remotehost>
Then start the script in this ssh session. The python script host must connect to localhost:5678 and of course your local pycharm debugger must listen to 5678
(or whatever port you choose)

pycharm ssh interpter No such file or directory

I am using a macbook pro 15 as local machine and I have a remote server running ubuntu 14.04
I want to use the remote intepreter to run all the computation but I want to write the code from my local machine.
When I try to run a simple file with pycharm I receive this error:
ssh://donbeo#149.157.140.205:22/usr/bin/python3 -u /Users/donbeo/Documents/phd_code/prova.py
bash: line 0: cd: /Users/donbeo/Documents/phd_code: No such file or directory
/usr/bin/python3: can't open file '/Users/donbeo/Documents/phd_code/prova.py': [Errno 2] No such file or directory
Process finished with exit code 2
I saw few people reporting the same problem but I haven't found a good answer so far. Most of the questions are indeed referring to older versions of pycharm.
It is clear that the file is not in my remote machine because I create it with pycharm in my local one. I was expecting pycharm to do some sort of synchronisation between the local and remote machine.
To execute your code on remote machine you'll have to perform few steps
Define a remote interpreter for your project
Go to File -> Settings -> Project: {project_name} -> Project Interpreter.
Click on cog icon and select Add Remote.
Add your SSH host credentials and interpreter path (on remote machine).
As a result, you should see new position in project interpreter dropdown selector, spelled like Python Version (ssh://login#host:port/path/to/interpreter). Package list should be populated with records.
Define deployment settings
Go to File -> Settings -> Build, Execution, Deployment -> Deployment
Create new deployment settings and fill ssh host configuration
Type: SFTP
SFTP host: same as interpreter host
Root path: path where files will be uploaded
Click on button "Test SFTP connection" to check if provided data are correct.
Go to mappings and configure mapping between local path and deployment path. Deployment path is relative to root path - / is equivalent to /my/root/path, /dir to /my/root/path/dir etc.
Deploy your code
Select Tools -> Deployment -> Upload to {deployment settings name}
Upload process will be started in background. Wait for upload to complete.
Run your code
Right click on file you want to run and select "Run". Code should run on remote machine.
Sometimes you can have everything set up correctly (interpreter, deployment, Path mapping, etc) but PyCharm keeps trying to use your local path on the remote machine.
If this happens, try this 4 fixes:
Go to File->Invalid Caches / Restart
...if the problem is still not fixed:
Go to Preferences->Python Interpreter->Path Mappings and check the path mappings of the interpreter. They should look more or less like this:
...again, if the previous step didn't work:
Go to Run->Edit Configurations... and check if the path mappings are correct:
You can also try to replace the local paths of the script and working directory with the remote ones (as if you were already in that machine).
If you get ModuleNotFoundError but the connection seems to work, go to Run->Edit Configurations...->Environment Variables and add your project's root path to the PYTHONPATH variable.
Be sure your interpreter is chosen as SSH which is to compile, not STFP which is for deployment.
I'm running PyCharm 2018.3
The Problem:
First, I didn't have the [Errno 2] No such file or directory problem. Then I had the problem out of nowhere.
The issue arose when I did:
Preferences -> Project: {project_name} -> Project Interpreter
Instead of "Click on cog icon and select Add Remote", I chose a interpreter that I've configured previously (that is working fine previously) from the drop down menu
By doing the steps above, I had [Errno 2] No such file or directory problem.
The reason is that the folder is not automatically synced to the remote server (a bug?), nor could I find a way to configure it to sync. Configuring Deployment and Path Mappings did work, but it's too much manual labor and prone to error.
The solution:
All I had to do is to add a new remote interpreter, despite that identical configurations already exists previously. (To be safe, I did remove the old ssh interpreter and the old deployments, also removed .idea folder) Then everything worked as expected.
I didn't need to configure Deployment
I didn't need to configure Paths mappings
It can be caused by one of the following:
1. You did not deploy your code on the remote server.!
Make sure that the recent edition of your code is deployed on the server. You can always deploy your code from Tools -> Deployment -> Upload to ..., or by using Ctrl + Shift + Alt + x.
For setting the deployment path, Go to File -> Settings -> Build, Execution, Deployment -> Deployment, and enter a remote sever details as your deploying machine.
In the Mappings tab, make sure that the deployment path is defined somewhere on the server where you have permission to read and edit files there.
2. You do not have the permission to read and change files on your deployment path at the remote server.
Go back to File -> Settings -> Build, Execution, Deployment -> Deployment, and change deployment path on the Mappings tab.
For those who meet the problem like "miniconda3/envs/gpu/bin/python: can't open file '///home/.../test.py", you can just run the python script file in locality in pycharm rather than run the file in server in pycharm.

Categories