PyCharm Remote Python Interpreter Across Platforms - python

Is it possible to work with a Windows python interpreter from an OS X PyCharm instance?
I'm developing some python code for the Windows environment (uses Windows-specific packages) but would like to stay in the OS X environment for all the development. I was hoping PyCharm's Remote Interpreter option over SSH would allow this, but I keep getting the following error. It appears after connecting OS X PyCharm to a Windows 10 Anaconda interpreter (over SSH).
Couldn't refresh skeletons for remote interpreter
failed to run generator3.py for sftp://[username]#[host]:22/Users/[username]/AppData/Local/Continuum/anaconda2/python.exe, exit code 1, stderr:
-----
'env' is not recognized as an internal or external command,
operable program or batch file.~
-----
A few (possibly) helpful pieces of info:
SSH server is the Windows 10 built-in OpenSSH
I get the above error even when I try connecting to the same remote interpreter (via SSH) from Windows PyCharm. This suggests to me that the issue isn't caused by mixing platforms.
Finally, I can connect to and interact with the desired Windows Anaconda interpreter from OS X PyCharm using the built-in Start SSH session (in the Tools menu). This also works from Windows PyCharm. Things start going south when I try to use it as the project interpreter.

This is not possible as of version 2019.1.3 released 29 May 2019. Pycharm doesn't support Windows remote interpreter. See the link below to the JetBrains issue tracker page discussing the desired functionality.
https://youtrack.jetbrains.com/issue/PY-20952

Related

LiClipse 8.1 on Mac OS 10.14.6 cannot run python interpreter (posix_spawn failed)

maybe someone has seen this..
fairly old Mac OS which might cause this, but mostly everything works OK:
Mac OS 10.14.6 (18G9323)
LiClipse 8.1.0.202110030926 com.brainwy.liclipse.rcp.product null
Homebrew freshly updated (even though also complains OS is too old) and some packages reinstalled to make sure it's all cleared
$ pyenv versions
system
3.9.5
* 3.9.7 (set by /Users/aanisimov/.pyenv/version)
$ which python
/Users/aanisimov/.pyenv/shims/python
$ python --version
Python 3.9.7
LiClipse just cannot find it! tried all these buttons there (PATH, pip, what not) still the same error:
Errors getting info on discovered interpreter(s).
See error log for details.
java.lang.RuntimeException: java.io.IOException: Cannot run program "/usr/bin/python": error=0, posix_spawn failed
java.lang.RuntimeException: java.io.IOException: Cannot run program "/usr/bin/python2.7": error=0, posix_spawn failed
java.lang.RuntimeException: java.io.IOException: Cannot run program "/usr/local/bin/python3": error=0, posix_spawn failed
java.lang.RuntimeException: java.io.IOException: Cannot run program "/usr/local/bin/python3.9": error=0, posix_spawn failed
looks like it is trying to find it in most obvious locations, but unable to spawn the process to run it?
Python works OK via terminal and things like Sublime Text.
Thanks for any advice!
See attached screenshot as well!
I had a problem very much like this, except with LiClipse version 8.2.0, running on macOS 12.4 Monterey, with Python interpreters installed by MacPorts. The symptoms were similar, except that LiClipse returned error code 316 instead of 0. What I wanted to know: how can I resolve this problem, so that LiClipse can add new interpreter entries in PyDev, and not display errors?
I came up with a workaround. I don't fully understand why it works, but I have some clues.
Workaround:
Install a standard Eclipse app of the same vintage (Eclipse 2021-12, version 4.22, corresponds to LiClipse 8.2.0).
Quit LiClipse.
Using a plain text editor, edit the file within LiClipse.app, LiClipse.app/Contents/Eclipse/LiClipse.ini. Change the lines in that file which read:
--launcher.defaultAction
openFile
-vmargs
to read (of course replacing <myuserid> with your home directory name, and no line break in the very long line starting "/Users/"…):
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vm
/Users/<myuserid>/.p2/pool/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.macosx.x86_64_18.0.1.v20220515-1614/jre/lib/libjli.dylib
-vmargs
save LiClipse.ini.
run LiClipse.app. It should now be able to add new interpreter entries in PyDev, with no errors.
delete the Eclipse.app. (This should leave behind /Users//.p2/ undisturbed.)
What it does:
I am not an expert on the internals of either LiClipse or Eclipse. What I think is happening is that Eclipse supplies an OpenJDK for the app to run, it is different than the OpenJDK supplied by LiClipse, and it supports recent version of macOS better. Evidence of difference:
% /Applications/LiClipse.app/jre/Contents/Home/bin/java --version
openjdk 14.0.2 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.2+12)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.2+12, mixed mode, sharing)
% /Users/<myuserid>/.p2/pool/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.macosx.x86_64_18.0.1.v20220515-1614/jre/bin/java --version
openjdk 18.0.1 2022-04-19
OpenJDK Runtime Environment Temurin-18.0.1+10 (build 18.0.1+10)
OpenJDK 64-Bit Server VM Temurin-18.0.1+10 (build 18.0.1+10, mixed mode)
The LiClipse.ini file controls how the app starts up. macOS runs a launcher program, and the launcher is guided by the contents of the ini file. The inserted lines look to me like they tell the launcher to specify a different Java VM to use when running the main Eclipse/LiClipse application — to use the OpenJDK 18.0.1 supplied by Eclipse, saved in ~/.p2/, instead of the OpenJDK 14.0.2 supplied by LiClipse; and also to invoke a library libjli.dylib.
Clues about the cause
I don't know enough about the JDK to know what library libjli.dylib does. There are clues in a StackOverflow answer, What is the Java libjli library for?, and in a blog post, Calling Java From C. It looks like it helps interaction between the Java VM environment and the hosts's native language environment. The StackOverflow reply mentions,
The libjli.so contains a launcher interface for preparing arguments passed in the command line and launching the virtual machine with them.…
The error message in my case read,
java.io.IOException: Cannot run program "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python": error=316, posix_spawn failed
I speculate that LiClipse was trying to call macOS to run the Python interpreter, but this attempt failed because the Java VM environment could not call the host's native environment successfully.
The change to LiClipse.ini means that LiClipse uses a different OpenJDK, and invokes libjli differently. The combination of these differences seems to let the Java VM environment succeed in calling the host's native environment.
I speculate that a proper fix requires an update to LiClipse. I have opened ticket 239, 8.2.0 cannot run pythons and pips, "java.io.IOException: Cannot run program"... error=316, posix_spawn failed, to track it.

PEP8 inspection in PyCharm not working with Docker remote python interpreter

I use local python interpreter, pep8 work well and I see all warnings in my files.
Then I switch to remote python interpreter from Docker, all warnings disappeared.
Python on local and Docker: 2.7.12
Pycharm: PyCharm 2017.3.3 (Professional Edition) Build #PY-173.4301.16, built on January 11, 2018
As explained here, Pycharm needs a local interpreter in order to inspect the code. For me, the following worked:
Create a new (dummy) project
Configure a local Python interpreter for the dummy project
Close Pycharm
Open Pycharm and then open your original project that uses the remote interpreter
PEP8 inspection works! (granted that it is enabled in the settings)
Basically my understanding is that it needs a local interpreter to be configured for some project but not necessarily for the specific project you want to run the inspection on.

Pycharm cannot find libraries from remote virtualenv, even when correct interpreter specified

I want to use Pycharm as IDE to upload my python code to a remote server. On this server I have a virtual environment with virtualenv. This interpreter is specified in the project interpreter settings and when I look at the installed packages, it finds all the packages, but when I program, all the imports I use are not found and hence autocomplete does not work and my whole code is full of errors which is quite annoying. I use Pycharm on a windows computer and the server runs on Ubuntu 14.04.
As can be seen on the figure, the project interpreter uses an ssh connection to the server, and my path to the python interpreter is set to the python interpreter of the virtual environment (not the default python on that server). All the installed packages are also shown. Should I configure something else to make Pycharm find these modules (allthough I think pycharm finds them as they show up in the picture, but it does not use them for imports)?
I had a similar problem, but not with a remote interpreter.
I found that the Run Configuration was set to use a different interpreter than the Project Settings.
Settings / Preferences > Project: untitled > Project Interpreter =>
~/project/venv/bin/python
All good. But:
Run Configuration > Python interpreter => /usr/local/bin/python3.7
The top choice on the drop-down list for the Run Configuration interpreters was Project Default which set it to the same as my project setting.
Run Configuration > Python interpreter => Project Default
(~/project/venv/bin/python)
I don't know if this is the cause of your problem, but it's something to check.
As discussed in PY-29551 PyCharm does not yet support remote virtual environments with remote interpreters (only global Python environments). Apparently they will add this any moment in PY-6002.
Until then I solved this with the workaround suggested in PY-29551:
For simply deploying and running code the workaround with adding a "pseudo" python executable that just loads the venv before running python worked for me:
#!/bin/sh
. /home/me/mypy/venv/bin/activate
exec python $*
Just add this to your remote venv and select it as Python executable instead.
For remote debugging this did not work for me, so for debugging I instead went for the Remote Debug Server approach described in the offical PyCharm docs on remote debugging.

How to setup python to use at Terminal in PyCharm

I am running PyCharm on a server without administrative acess.
The server has Python 2.7 installed.
I am using Anaconda3 Python 3.5.3 when running programs and in the Console.
However, I cannot find where to set the Terminal of PyCharm to the same Python (Anaconda3/Python 3.5.3)
It keeps using the 2.7 and I cannot delete it from the server.
Thanks.
Appreciate the help.
You have to set up the path to the correct python binaries, when you add the remote interpreter in PyCharm:
Write there the path to your anaconda installation. So in your case the Python interpreter path is something like:
/your_install_path/anaconda/bin/python3

Define remote interpreter on remote Linux machine using Pydev and RSE Server

I have a Windows box and a Linux red hat box.
Eclipse is installed on Windows, following instructions given on this eclipse page. I managed to set up a RSE server that runs on the Linux box; I am also able to create a project on the remote machine.
Actually I am using virtual environments on Linux and I would like to select them when developing.
Is there a way to define a remote interpreter for a PyDev or Django project?
I once had the same problem with a remote python interpreter inside an Ubuntu virtual machine. I guess you should be able to connect through ssh in your case also.
Although Pycharm can have remote interpreters (even with virtual machines using Vagrant), some people like me prefer editors like Sublime Text 3, i.e., not IDE. There, you can specify a path to any interpreter within your host machine. I guess Pydev also allows to specify a python interpreter inside the host.
The easiest way (but maybe not the nicest) I could find to use a remote interpreter, was to mount the environment folder (where the python executable and modules were) of the virtual machine in my host. So, here's what you can do:
In the virtual machine (the guest) --> create a virtual environment in any path you want, for example, ~/myGuestEnvs/testEnv/. You can do this using virtualenv, which you previously installed with pip.
In your host --> install win-sshfs and mount the correspondent folder of the virtual machine in your host like this ~/myGuestEnvs/testEnv/ --> ~/myHostMountedFolder/. If I understood well, you are coding from Windows and running the code on Linux. I must admit that it isn't the easiest to mount disks through ssh on Windows, but it still possible! You can check out this SoF question for other ways.
Always in your host --> point your python interpreter to the mounted folder: python_interpreter --> ~/myHostMountedFolder/bin/python.
Careful, if you only mount/point the bin folder of the environment, where the python executable is, you will lost all the code completion, goto definition... usabilities of the IDE, since it won't be able to locate your imported modules.
I should add that if the virtual machine is down, then Pydev won't be able to use the python_interpreter since the mounted folder will be empty. Everytime you code, you will have to start the virtual machine, if not, then it is possible that the default host python interpreter and host python packages are used.
Pycharm IDE support running your project/program from Remote Interpreter also the support deploying to remote server(which comes as part of Pro version).
Pycharm also does support Git/Vagrant/GoogleApp Engine.
The only product for Python I managed to get working in this manner (like Eclipse debugging remote code in Java) like this is (commercial, proprietary) WingIDE.
I managed to achieve this by doing the following:
1) Create a python venv
python3 -m venv /home/me/venv
2) Set pydev interpreter to the venv by going to Window->Preferences->PyDev_Interpreters->Python Interpreter-> Browse for python/pypy
3) Backup the python executable if needed:
mv /home/me/venv/bin/python3 /home/me/venv/bin/python3.bkp
4) Create a new python executable with the same name:
nano /home/me/venv/bin/python3
5) Paste the following content:
#!/bin/bash
remote_username=me
remote_interpreter=python3
remote_hostname=10.0.0.1
file_path=(${2//$remote_hostname/ })
ssh $remote_username#$remote_hostname "$remote_interpreter $1 ${file_path[1]}"
6) Change remote_username, remote_interpreter and remote_hostname to match your configurations.
Enjoy !

Categories

Resources