2

Oct. 2021 update: I am at my wit's end over this. Still Windows 10, official GNU emacs 27.2. Anaconda installed in c:\users\[username]\Anaconda3. No venv's, I just use the base conda environment. Please please tell me what exactly to type in my .emacs file, so that "M-x run-python" starts the anaconda python, properly activates so "import numpy" works. Please! I've flailed around w/ pyvenv.el, conda.el, I give up.

I have a Windows 10 machine, with the official GNU emacs Windows build, and Anaconda Python 3.7.3. I can't get Python to properly run within emacs. Whenever I start Python, I get the message:

Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32

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

Type "help", "copyright", "credits" or "license" for more information.

And numpy, scipy, etc won't load. I have tried several things with the pyvenv and elpy packages, all to no avail. From a DOS prompt, I type 'activate' to activate the conda env. I haven't setup any venv's of my own.

3
  • From the warning message in your posting - see this page: docs.conda.io/projects/conda/en/latest/user-guide/tasks/… for detailed windows configuration.
    – Ian
    Jul 13 '19 at 15:25
  • Try conda.el package github.com/necaris/conda.el/blob/master/conda.el It switches between conda environments
    – mmmmmm
    Oct 7 at 8:31
  • Thanks, but I can't figure out how to get this to work. By "work", I mean "M-x run-python" starts Anaconda python, with the env activated so numpy works. I have "(require 'conda)" in my init.el, and with or without "'(conda-anaconda-home "c:/Users/strozzi2/Anaconda3")" it doesn't work. "M-x conda-env-list" works (so the package is loaded) but lists nothing. "M-x conda-env-activate" asks what env to activate. <blank> and "base" both give "No such conda environment." I am stumped.
    – D Strozzi
    Oct 8 at 16:37
1

Provided that you added the folders paths of your conda install in Windows' %PATH% variable[*], the following should work :

  1. M-x shell

  2. In the shell, run conda activate base. This will load the environment and allow you to use the libraries (like numpy).

  3. In the same shell, run python -i (or ipython -i). The -i forces a prompt. Without it, the shell hangs in Emacs, I don't know why (it doesn't in cmd).


I personally automated this process by creating a batch file called my-python.bat. I placed it in a folder named my-batch-files which I have referenced in %PATH% [*]. Here's the bat file :

@echo off
conda activate base && python -i

That way you can call directly my-python from the shell — whether it be on Emacs or on cmd — and have a working ipython shell, with all DLLs loaded.

Plus, if you change python-shell-interpreter to my-python, you get the default functions from python-mode run-python (C-c C-p) and python-shell-send-buffer (C-c C-c) working.

Caveat : At this time, images' display (with matplotlib.pyplot) still does not work properly. I'm working on it. If someone has ideas...


[*] Windows -> Environment variables -> System Variables -> Path -> Edit. The paths should look like this (check them beforehand !) : C:\Users\YOUR_USER_NAME\AppData\Local\Continuum\anaconda3\Scripts and C:\Users\YOUR_USER_NAME\AppData\Local\Continuum\anaconda3.

You'll have to relaunch the shell (and Emacs !) for the environment variables to be taken into account. You can check the variable value by typing echo %PATH% in your shell.

1
  • Note: this worked for my replacing conda activate base with just activate base.
    – pglpm
    Apr 4 '20 at 15:22
-1

This solved my issue of numpy failing to load on import when using Anaconda3/python on Windows 10 from my Emacs session:

https://github.com/ContinuumIO/anaconda-issues/issues/10884#issuecomment-499805821

1
  • 1
    Welcome to emacs.SE! Please avoid providing link-only answers. Try to summarize how the issue is solved, this is will make it potentially much more usefull in the future.
    – JeanPierre
    Oct 7 '19 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.