-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Activating venv on Windows 10 #1628
Comments
From what happen, It looks like a problem in In any case, pyvenv works by setting a bunch of variables in Emacs.
|
Thanks for the response. I turned off elpy, and every variable agrees with what you said, except exec-path has c:/.../anaconda3/Scripts but not bin/. anaconda3/ has no bin dir, but there is a condabin/. I added that to exec-path, same problem. Note that on Windows I'm sure one has to run various .bat files instead of the shell scripts, e.g. activate.bat not activate. |
You are right, It may be related to this issue. (defun pyvenv-activate (directory)
"Activate the virtual environment in DIRECTORY."
(interactive "DActivate venv: ")
(setq directory (expand-file-name directory))
(pyvenv-deactivate)
(setq pyvenv-virtual-env (file-name-as-directory directory)
pyvenv-virtual-env-name (file-name-nondirectory
(directory-file-name directory))
python-shell-virtualenv-path directory
python-shell-virtualenv-root directory)
;; Set venv name as parent directory for generic directories
(when (member pyvenv-virtual-env-name '("venv" ".venv"))
(setq pyvenv-virtual-env-name
(file-name-nondirectory
(directory-file-name
(file-name-directory
(directory-file-name directory))))))
;; Preserve variables from being overwritten.
(let ((old-exec-path exec-path)
(old-eshell-path eshell-path-env)
(old-process-environment process-environment))
(unwind-protect
(pyvenv-run-virtualenvwrapper-hook "pre_activate" pyvenv-virtual-env)
(setq exec-path old-exec-path
eshell-path-env old-eshell-path
process-environment old-process-environment)))
(run-hooks 'pyvenv-pre-activate-hooks)
(let ((new-directories (append
;; Unix
(when (file-exists-p (format "%s/bin" directory))
(list (format "%s/bin" directory)))
;; Windows
(when (file-exists-p (format "%s/Scripts" directory))
(list (format "%s/Scripts" directory)
;; Package dlls to be loaded at runtime
(when (file-exists-p (format
"%s/Library/bin"
directory))
(format "%s/Library/bin" directory))
;; Apparently, some virtualenv
;; versions on windows put the
;; python.exe in the virtualenv root
;; for some reason?
directory)))))
(setq pyvenv-old-exec-path exec-path
pyvenv-old-eshell-path eshell-path-env
pyvenv-old-process-environment process-environment
;; For some reason, Emacs adds some directories to `exec-path'
;; but not to `process-environment'?
exec-path (append new-directories exec-path)
;; set eshell path to same as exec-path
eshell-path-env (mapconcat 'identity exec-path ":")
process-environment (append
(list
(format "VIRTUAL_ENV=%s" directory)
(format "PATH=%s"
(mapconcat 'identity
(append new-directories
(split-string (getenv "PATH")
path-separator))
path-separator))
;; No "=" means to unset
"PYTHONHOME")
process-environment)
))
(pyvenv-run-virtualenvwrapper-hook "post_activate")
(run-hooks 'pyvenv-post-activate-hooks)) |
Thanks for this! It has the same problem as the original, at least the way I'm using it. Namely, the relevant lines in my .emacs.d are: I restart emacs, M-x run-python, same error as before ("This Python interpreter is in a conda environment, but the environment has not been activated." Then import numpy fails). Maybe I need to do something else? |
Sorry to nag, but does anyone have any bright ideas on this issue? Anythin I can try? Thanks. |
I was on holidays for a while, I am trying to catch up. The issue in pyvenv seems to indicate that So would this help ?
|
Thanks for replying! Same issue with your suggestion ("This Python interpreter is in a conda environment, but the environment has not been activated....."). FWIW attached is my init.el, which I cut down to a bare minimum. |
Sorry, I am a bit out of ideas. Your init file works fine for me, but I don't have a computer with windows 10 and Emacs installed. As this is not really a problem with Elpy but more with Pyvenv, you may have more luck reporting there. |
Summary
I can't get a venv to activate on Windows 10.
Steps to reproduce
M-x run-python
Anaconda python 3.7.3 starts, but gives this warning:
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
import numpy # gives error, DLL load failed, typical on Windows when venv not setup
My configuration
OS
GNU emacs 26.2 (straight from GNU) on Windows 10. Oddly, I didn't have this issue on Win7 last year. I did have others, like getting plots in ipython to work, but one step at a time!
Result of
(elpy-config)
Elpy configuration in my init.el
Thanks!
The text was updated successfully, but these errors were encountered: