0

I have a local Python installation in //anaconda/bin/python

In the command prompt

$python
>>import sys
>>print sys.executable
>>//anaconda/bin/python

but, in emacs I get

M-x shell
bash-3.2$ python
>>import sys
>> print sys.executable
>> /usr/bin/python

How can I set my path to use the desired Python in the emacs shell?

Iguananaut
  • 21,810
  • 5
  • 50
  • 63
ljofre
  • 314
  • 5
  • 18
  • I'm not familiar with emacs so I couldn't tell you off hand, but presumably there is a way to set your `$PATH` in the emacs shell to prepend it with /anaconda/bin. Google appears to have many answers to this. It has little in particular to do with Python. – Iguananaut Mar 09 '14 at 06:21

3 Answers3

0

You need to set the PATH environment variable that emacs uses.

Check out How do I make Emacs recognize bash environment variables for compilation?

Specifically this: https://github.com/purcell/exec-path-from-shell

On OS X, an Emacs instance started from the graphical user interface will have a different environment than a shell in a terminal window, because OS X does not run a shell during the login. Obviously this will lead to unexpected results when calling external utilities like make from Emacs.

This library works around this problem by copying important environment variables from the user's shell.

Community
  • 1
  • 1
demented hedgehog
  • 7,007
  • 4
  • 42
  • 49
0

As demented hedgehog wrote, you need to modify your PATH environmental variable in emacs. Specifically, add this line in your ~/.emacs or ~/.emacs.d/init.el file, depending on where your init file is.

(setenv "PATH"
    (concat
     "//anaconda/bin:"
     (getenv "PATH")
     )
    )
ysakamoto
  • 2,512
  • 1
  • 16
  • 22
0

Just for completeness: at Linux simply starting emacs from shell will read the current path in.

Andreas Röhler
  • 4,804
  • 14
  • 18