• Eshell and Python venv

    From Rust Buckett@rsstinnett@pm.me to gnu.emacs.help on Sat Jan 10 23:00:55 2026
    From Newsgroup: gnu.emacs.help


    Is there a way to activate a Python virtual environment in Eshell? When
    I try `source ./.venv/bin/activate`, I get "Wrong type argument: listp,
    "["". Obviously, this is because `source` is built into the shell
    (bash, csh, fish, eshell, etc.) and the default activate is for bash.
    So, I guess the real question is if there is already a script to
    activate the venv in eshell? Or some other way to do it?
    --
    this is my clever sig.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Manuel Giraud@manuel@ledu-giraud.fr to gnu.emacs.help on Sun Jan 11 12:48:22 2026
    From Newsgroup: gnu.emacs.help

    Rust Buckett <rsstinnett@pm.me> writes:

    Is there a way to activate a Python virtual environment in Eshell? When
    I try `source ./.venv/bin/activate`, I get "Wrong type argument: listp,
    "["". Obviously, this is because `source` is built into the shell
    (bash, csh, fish, eshell, etc.) and the default activate is for bash.
    So, I guess the real question is if there is already a script to
    activate the venv in eshell? Or some other way to do it?

    If you read "./.venv/bin/activate", you'll see that what it do mostly is setting VIRTUAL_ENV to "./venv" and add "$VIRTUAL_ENV/bin" to your PATH
    to access the "correct" python.

    So doing the following should work:
    export VIRTUAL_ENV="/absolute/path/to/venv"
    export PATH="$VIRTUAL_ENV/bin":$PATH

    But maybe you could come up with an elisp function to more easily
    activate (and deactivate) those.
    --
    Manuel Giraud
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Rust Buckett@rsstinnett@pm.me to gnu.emacs.help on Sun Jan 11 07:05:46 2026
    From Newsgroup: gnu.emacs.help

    Manuel Giraud <manuel@ledu-giraud.fr> writes:

    Rust Buckett <rsstinnett@pm.me> writes:

    Is there a way to activate a Python virtual environment in Eshell? When
    I try `source ./.venv/bin/activate`, I get "Wrong type argument: listp,
    "["". Obviously, this is because `source` is built into the shell
    (bash, csh, fish, eshell, etc.) and the default activate is for bash.
    So, I guess the real question is if there is already a script to
    activate the venv in eshell? Or some other way to do it?

    If you read "./.venv/bin/activate", you'll see that what it do mostly is setting VIRTUAL_ENV to "./venv" and add "$VIRTUAL_ENV/bin" to your PATH
    to access the "correct" python.

    So doing the following should work:
    export VIRTUAL_ENV="/absolute/path/to/venv"
    export PATH="$VIRTUAL_ENV/bin":$PATH

    But maybe you could come up with an elisp function to more easily
    activate (and deactivate) those.

    I realized that since you can evaluate elisp functions in eshell as you
    would commands, I'm able to run `pyvenv-activate .venv` right in the
    shell. This /almost/ works. `exec-path` shows the correct path and
    `getenv "PATH"` shows the change, but `echo $PATH` does not. Guess
    which one eshell uses.

    If I run `pyvenv-activate .venv` then exit eshell and start it again, everything works. It's not as elegant as I would like, but I guess it
    will have to do.
    --
    this is my clever sig.
    --- Synchronet 3.21a-Linux NewsLink 1.2