Environmen PATH with Pycharm remote connection - python

I have a remote server and I want to use Pycharm to execute my scripts on this remote server using SFTP and SSH. Everything works properly, except that, when running the scripts on the server through the Pycharm "Run" command, the PATH is wrong. I am trying to understand which file I should edit to properly set the PATH environmental variable. I am using a mac and the server runs ubuntu. After having installed several libraries on the server, I edited the .bashrc file in my home directory on the server to properly set up the PATH. Then the following happens:
If I login to the server using ssh and the mac terminal, the PATH is loaded correctly.
If I open a ssh session inside pycharm and connect to the server, the PATH is loaded correctly.
If I run a simple script (that only contains calls to the standard library) on the remote server through the Pycharm "Run" command, it works
If I run the full script on the remote server through the pycharm "Run" command, then in crashes: os.environ['PATH'] shows that the path is not correct
If I run the script by directly calling the python interpreter on the server using one of the terminal ssh session, then the PATH is set up properly and it works
So apparently the PATH is set up properly if I connect to it using ssh and the terminal, but when Pycharm tries to run it directly the PATH is not updated and it crashes.
So I am guessing pycharm doesn't look into .bashrc before running the program. Which file should I modify then? Note that the only "configuration" files present in my home directory on the remote server are .bashrc and .profile.
Note I do not have sudo privileges on this server.

Related

PyCharm Error when setting remote interpreter -> Run Error: Jupyter server process failed to start due to path mismatch issue

I am trying to setup remote development on PyCharm. For this, I want to make changes locally and execute the code on remote Amazon EC2 instance with a remote interpreter. I had done the following configuration of the project, but I am getting run error when I try to execute a ipython file created locally.
Cannot run program "stfp://<remote server hostname>/<remote server host>:<remote interpreter path>" (in directory <local folder directory>): error=2, No such file or directory.
It seems it should open <remote folder directory> instead of <local folder directory> when running the program. I read through multiple setup instructions but could not get this fixed. I am attaching configuration below.
Can you please help me with what could be wrong?
Updating PyCharm to 2022.3 can fix the issue. This seems to be related to an unstable older version.

Can't run Python Script on remote VM via SSH

I have an Azure VM into which I SSH in. The VM is a W10 host.
I can create files with touch, change directories and so on, but whenever I try to run a python script that is hosted on the VM I get the following error:
The system cannot execute the specified program.
At first glance I thought that there was a problem related to my pyhton alias and the PATH variable, so I decided to use RDP to log into the machine, open a CMD and try the same command, which worked just fine. The python program executed flawlessly.
I used where to find where is my python.exe located at, so whenever I run the script on my remote terminal I can do something like:
C:\Users\User01\AppData\Local\Microsoft\WindowsApps\python.exe test.py
This does result in the same error message as the one stated above.
Can I get some help?
Hi try to execute your command as below.
ssh user#machine python < script.py

ssh running a command gives different results to running it locally

I have a python script that uses Popen to create an appium server for a simulator on a mac
self.appium_process = subprocess.Popen(["/usr/local/bin/appium", "-a", self.ip, "--nodeconfig", self.node_file_path, "--relaxed-security", "-p", str(appium_port), "-dc", default_capabilities], stdout=log_file, stderr=subprocess.STDOUT)
I created a bash shell script that calls the python script. When I run the script from the local box it works and the appium logs show the connection.
I need to run this remote via ssh however. So I use the following to call the script:
ssh 10.18.66.99 automation_fw/config/testscript.sh
This, however, always ends up with the log showing:
env: node: No such file or directory
I checked and the node app has an extra slash before its called:
$ which node
/usr/local/bin//node
$
I tried changing the path on the machine but no change. How can I get this to run from ssh in the same way as it can run locally on that same box
A
When you are running a command vis SSH you are not starting what's called a login shell (more about that here).
From the details you've shared, I would say it's some thing in your environment (running outside a logged-in shell), more specifically a problem with your $PATH variable. You might want to check /etc/environment or similar paths (depending on your Linux flavour) for the wrong value.

Opening script saved on a cluster with local spyder installation

I have anaconda, hence spyder, installed on a local machine. What I am trying to do is to use my local spyder installation to open a .py script saved on a remote cluster (in my office) via ssh. The issues that I am encountering are the following:
I cannot run spyder from the cluster - there is no graphical device whatsoever. For example, we have actually anaconda installed on the cluster, but when I ran spyder from the command line, I get the following error message: Could not connect to any X display
I cannot mount the (remote) drivers, where the .py scripts are located, onto my local machine when I am working from home (which is the case when I am at work, connected to the internet via cable). If this was the case, I could simply launch spyder on my local machine, then open the scripts. I can only access the files on some drivers mounted onto the cluster via ssh.
As, however, I can access the .py scripts saved on the cluster via ssh (I can open then with programs installed locally e.g. vim, jpico etc), I was wondering whether it is possible to use the command line to open a script saved on a remote cluster using my local spyder installation, something like $ spyder /path/to/myScript/savedOnTheRemoteCluster.py
(Spyder maintainer here) As of May 2019 our editor is not capable of working with files on remote locations. So your best option right now is to mount your remote server with sshfs to make it appear as a local directory and then open any file present there in Spyder.

How to run a python script on a remote ec2 instance using sudo from pycharm

I am running pycharm 2017.2.3. I want to run my python script on a remote ec2 instance using sudo user through pycharm. How do I acieve this?
Follow the steps below:
Go to File -> Settings -> Project Interpreter and add a new interpreter
Click on + to add a new python interpreter and then click on SSH interpreter
Provide your EC2 Public DNS in HOST and ubuntu as username
Click Next and add the private_key.pem file.
See this article for more details:
PyCharm setup for AWS automatic deployment
It looks like you can configure your python interpreter over SSH with the professional version of PyCharm.
Configuring Remote Interpreter + PyCharm
Finally found an answer after a researching through the internet. We can have a script on remote machine as a pycharm interpreter. Create a following script on a remote machine and make sure the script is executable.
#!/bin/bash
sudo /usr/bin/python "$#"
Now change the project interpreter to point to the above script on remote machine in pycharm. Now every script you run on local machine gets executed on remote as a sudo user.

Categories