I am using Eclipse on Linux to develop C applications, and the build system I have makes use of make
and python
. I have a custom virtualenv installed and managed by pyenv
, and it works fine from the command line if I pre-select the virtualenv with, say pyenv shell myvenv
.
However I want Eclipse to make use of this virtualenv when building (via "existing makefile") from within Eclipse. Currently it runs my Makefile but uses the system python in /usr/bin/python
, which is missing all of the packages needed by the build system.
It isn't clear to me how to configure Eclipse to use a custom Python interpreter such as the one in my virtualenv. I have heard talk of setting PYTHONPATH
however this seems to be for finding site-packages rather than the interpreter itself. My virtualenv is based on python 3.7 and my system python is 2.7, so setting this alone probably isn't going to work.
I am not using PyDev (this is a C project, not a Python project) so there's no explicit support for Python in Eclipse. I'd prefer not to install PyDev if I can help it.
I've noticed that pyenv adds its plugins
, shims
and bin
directories to PATH when activated. I could explicitly add these to PATH in Eclipse, so that Eclipse uses pyenv to find an interpreter. However I'd prefer to point directly at a specific virtualenv rather than use the pyenv machinery to find the current virtualenv.
I had the same trouble and after some digging, there are two solutions; project-wide and workspace-wide. I prefer the project-wide as it will be saved in the git repository and the next person doesn't have to pull their hair.
For the project-wide add /Users/${USER}/.pyenv/shims:
to the start of the "Project properties > C/C++ Build > Environment > PATH".
I couldn't figure out the other method fully (mostly because I'm happy with the other one) but it should be with possible to modify "Eclipse preferences > C/C++ > Build > Environment". You should change the radio button and add PATH variable.
For me, following steps worked ( mac os 10.12, eclipse photon version, with pydev plugin)
In the bottom libraries section, you should be able to see the site-packages from your virtual env
Extra tip - In my mac os the virtual env was starting with .pyenv, since it's a hidden directory, I was not able to select this directory and I did not know how to view the hidden directory in eclipse file explorer. Therefore I created an softlink ( without any . in the name) to the hidden directory (.pyenv) and then I was able to select the softlink
Typing CMD+SHIFT+. will show you dotfiles & directories that begin with dot in any Mac finder dialog box...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.