How to use python remote interpreter in CLion - python

I want to use remote Python Interpreter in CLion, and I do not find corresponding config in Clion.
I have try to config in Preferences >> Build, Execution, Deployment >> Python Interpreter.
But I don't find where to config a remote Python Interpreter in CLion.Here is the config page for Python Interpreter but not where for remote interpreter.

CLion has Community Python plugin inside. That means it does not support remote Python Interpreter.

Related

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.

Is it possible to easily extract python run configuration (with additional path) from Pycharm?

I have a working Python project on my PC, which I am running from Pycharm.
It uses Pyroot (an interface to Root C++ library), whose C++ lib path I have added in Project Settings/Python Interpreter/Paths in Pycharm. It also needs to use the 2.7 Python interpreter, instead of 3., which is a default python in my terminal.
I want to run this project remotely on another desktop, so I need to be able to run it from terminal specifying the path to Root and the interpreter version.
Is there a way to easily extract from Pycharm the exact run command it is using when I'm running the code via run button?
Alternatively, if that's impossible, how should I specify the path to Root and the interpreter version when running from terminal?
I guess to best way is to create a virtualenv either in the terminal or in pycharm including the corrext python version 2.7 and install pyroot via pip into this virtualenv. Then you can simply ssh in the remote host, activate the venv and start your project from the terminal. Or you ssh into it with X-forwarding and start Pycharm itself from your client.
If you select the correct project and go to File > Settings, under the Project Settings you can see the Project Interpreter which tells you which interpreter is being used.
Hope this is what you are looking for.

Issue with path to python/pythonpath

I have a VPS with system-wide installed python 2.5.
I installed python 2.7 to one of the user's home dir (using --prefix). added it to bashrc and bash_profile, exported python variable to env, and now when I type python in console python 2.7 is running.
But when I checked python version from my application (Django using with FastCGI) I still see that it is using 2.5.
In ps output I see python processes running for this account and apache processes runing with hosting-specific account. How can I switch this particular account to 2.7 without changing system-wide version?
Thanks!
One option is to use the python virtualenv tool to create a Python virtual environment that you can source in your .bashrc.
mike#tester:~$ virtualenv --python=/usr/bin/python3 $HOME/fcgi_python
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in fcgi_python/bin/python3
Also creating executable in fcgi_python/bin/python
Installing Setuptools..............................................................................................................................................................................................................................done.
Installing Pip.....................................................................................................................................................................................................................................................................................................................................done.
mike#tester:~$ python --version
Python 2.7.5+
mike#tester:~$ source $HOME/fcgi_python/bin/activate
(fcgi_python)mike#tester:~$ python --version
Python 3.3.2+
In the example above you would replace the argument after --python= with the path to the Python interpreter installed in the user's home directory.
I had a call to python interpreter via env program in my fast cgi dispatch script. When I explicitly put path to 2.7 to the first line of the script it works as expected.
I've set PYTHONPATH in my /home/me/.bashrc and all worked ok from terminal, but when Apache w/ mod_wsgi starts my python scripts, it acts under sysem or dedicated user, which knows nothing of my .bashrc.
For this particular situation, I just used apache config (apache2.conf) to set python path for apache (WSGIPythonPath option).

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