Modify the emacs shell path environment

Do you remember this article? Traditional and Simplified Chinese convert under emacs.  In that, I use hancovnert emacs lisp to convert between simplified Chinese and traditional Chinese and vice versa.  Actually, it works on my T430 which is an Ubuntu platform but doesn’t work on my Mac.
I don’t remember it worked on it or not, but it doesn’t anyway. I studied the situation. The error message is that in emacs the python can’t import a module called chardet, but when I use pip to install it again it shows already exist. The results from

which python

are different between the terminal and emacs shell. Terminal uses /usr/local/bin/python but emacs shell uses /usr/bin/python, the later one doesn’t recognize the pip installed modules.
Now, easy, the solution is that let emacs call the right python, put the /usr/local/bin to the highest priority, then problem solved.
Simple, add one line in the .emacs to change the shell’s $path.

 (setenv "PATH" (concat "/usr/local/bin" ":" (getenv "PATH")))

 

Leave a Reply

Your email address will not be published. Required fields are marked *