I’m trying to learn Emacs developing for Python and I have discovered some of my projects don’t work because of modules import problem, namely SciPy or NumPy are not imported. I’ve tried solutions proposed for related questions asked here, like changing PYTHONPATH environment variable, but none was good. Having compared sys.path when using IDLE and plain interpreter from terminal I have figured out different versions are used: Python-2.7.3 in IDLE
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>> from pprint import pprint as pp
>>> import sys
>>> pp(sys.path)
['/home/mench',
'/usr/bin',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
'/usr/lib/python2.7/dist-packages/ubuntuone-couch',
'/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']
and Python-2.7.2 as default system interpreter
Python 2.7.2 (default, Mar 1 2012, 22:28:45)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pprint import pprint as pp
>>> import sys
>>> pp(sys.path)
['',
'/home/mench',
'/opt/alps/lib',
'/usr/local/lib/python27.zip',
'/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-linux2',
'/usr/local/lib/python2.7/lib-tk',
'/usr/local/lib/python2.7/lib-old',
'/usr/local/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']
Question is: How can I make Emacs use a proper version of Python?
I’m using GNU emacs-23.3.1 on Ubuntu 12.04
Please correct me if my assumptions about the problem are wrong
I think the problem is that wrong python executable is chosen. Normally
sys.pathfor modules is set appropriately if you install modules in normal ways (pip, setup.py, etc.).The problem is that you have manually installed python 2.7.2 in
/usr/local/binwhich comes before/usr/binin$PATHnormally. This is why your default python in the terminal is 2.7.2. To explicitly tell Emacs that you want to use python in a specific path (i.e.,/usr/bin/python), you need some Emacs configuration for python-mode.There are some python modes for Emacs but I am guessing you are using “old” python.el, as you are using Emacs 23. To set python executable, I think adding this in your Emacs configuration does the job (But I never use this python-mode so I am not sure if it works.):
You will need to re-open the python file after evaluating this code. Or simply just reboot Emacs.
If you use the new python.el, you have to add
/usr/bin/topython-shell-exec-path. If you are using python-mode.el, I guess it’s(setq py-shell-local-path "/usr/bin/python" py-use-local-default t).