GNU bug report logs - #24464
25.1; python.el virtualenv

Previous Next

Package: emacs;

Reported by: Pim <pim.remkes <at> upcmail.nl>

Date: Sun, 18 Sep 2016 23:51:02 UTC

Severity: normal

Tags: fixed, patch

Found in version 25.1

Fixed in version 26.1

Done: Noam Postavsky <npostavs <at> users.sourceforge.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: Justin Timmons <justinmtimmons <at> gmail.com>
Cc: Pim <pim.remkes <at> upcmail.nl>, 24464 <at> debbugs.gnu.org
Subject: bug#24464: 25.1; python.el virtualenv
Date: Mon, 16 Oct 2017 21:24:24 -0400
retitle 24464 python virtualenv support doesn't work on w32
quit

Justin Timmons <justinmtimmons <at> gmail.com> writes:

> It looks like this was caused by an incorrect assumption on the
> directory structure of the virtualenv directory. According to the
> virtualenv docs only POSIX systems follow the structure
> "/path/to/venv/bin/", while windows systems use "/path/to/venv/Scripts"
> for the location of the binary files, most importantly including the
> python interpreter (see:
> https://virtualenv.pypa.io/en/stable/userguide/#windows-notes).
>
> This meant that the wrong path was added to `exec-path` and so we were
> starting the python shell installed on the system, rather than the one
> bundled inside of the virtualenv.
>
> This should be addressed in the attached patch file - it just adds a
> special case for Windows and prepends that path to the system PATH.
>
> I also updated the docs for the `python-shell-calculate-exec-path`
> function to make it more clear that using the python interpreter bundled
> in the virtualenv will automatically set the PYTHONPATH to point at the
> libraries inside of the virtualenv - something that was not immediately
> obvious to me.


>  (defun python-shell-calculate-exec-path ()
>    "Calculate `exec-path'.
>  Prepends `python-shell-exec-path' and adds the binary directory
> -for virtualenv if `python-shell-virtualenv-root' is set.  If
> -`default-directory' points to a remote host, the returned value
> -appends `python-shell-remote-exec-path' instead of `exec-path'."
> +for virtualenv if `python-shell-virtualenv-root' is set - this
> +will use the python interpreter from inside the virtualenv when
> +starting the shell.  If `default-directory' points to a remote host,
> +the returned value appends `python-shell-remote-exec-path' instead
> +of `exec-path'."
>    (let ((new-path (copy-sequence
>                     (if (file-remote-p default-directory)
>                         python-shell-remote-exec-path
> -                     exec-path))))
> +                     exec-path)))
> +
> +        ;; Windows and POSIX systems use different venv directory structures
> +        (virtualenv-bin-dir (if (eq system-type 'windows-nt) "Scripts" "bin")))
>      (python-shell--add-to-path-with-priority
>       new-path python-shell-exec-path)
>      (if (not python-shell-virtualenv-root)
>          new-path
>        (python-shell--add-to-path-with-priority
>         new-path
> -       (list (expand-file-name "bin" python-shell-virtualenv-root)))
> +       (list (expand-file-name virtualenv-bin-dir python-shell-virtualenv-root)))
>        new-path)))

Looks good to me.  Have you assigned copyright for Emacs?  (The patch is
small enough to go in regardless, I only ask to know if we should mark
it.)




This bug report was last modified 7 years and 196 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.