Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
190 views
in Technique[技术] by (71.8m points)

python - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. 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.

  2. 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.

  3. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...