Search code examples
pythonwindows-10anacondacodexl

How to get an executable Python path out of an Anaconda environment?


I am trying to profile my pyopencl project with CodeXL, and in order to work with .py files. I can't think of anything better than pointing at Python.exe and passing path to script as an argument. What makes things complicated is my use of Anaconda virtual environment to resolve conflicts between modules, because this way it is impossible to simply point CodeXL at a python executable in some virtual environment - as far as I understand, this environment has to be activated first, and CodeXL does not support this.


Solution

  • The Python executable of a conda, virtualenv or venv environment is generally located at

    $ENVPATH/bin/python
    

    EDIT: on Windows should be instead (at least for venv)

    $ENVPATH\Scripts\python.exe
    

    where $ENVPATH is the environment path. To get a list of the environments you created along with their paths you can run (from the terminal)

    conda env list
    

    Alternatively, if you are using a Python interpreter and you want to know where its executable is located, you can run

    import sys
    print(sys.executable)