Basically, I am trying to have a good python development environment for sckit image and sklearn.

However, it seems to me the python version that runs in the emacs environment is different than the one in the system.

Python Shell in Emacs

Python Shell in OS Terminal

The main issue being certain libraries seem to be missing from the version on emacs when running this code

from skimage.viewer import ImageViewer
image = data.coins()
viewer = ImageViewer(image)

I get these errors.

    >>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mods/Work/DR_Research/sample/imageProc.py", line 9, in <module>
    viewer = ImageViewer(image)
  File "/Library/Python/2.7/site-packages/skimage/viewer/viewers/core.py", line 194, in __init__
  File "/Library/Python/2.7/site-packages/skimage/viewer/utils/core.py", line 29, in init_qtapp
    QApp = QtWidgets.QApplication.instance()
AttributeError: 'QtGui_cls' object has no attribute 'QApplication'

I have tried setting all sorts of variables from in the init-file py-shell interpreter, py-shell command, python-python command. I have tried appending the $PATH. All to no avail always the same version python 2.7.6 is being used in emacs

The same code runs normally on the os terminal. I only guessed that the different versions are the cause of the issue but it may be something else. I am kind of an amateur in python so detailed explanation is appreciated

Output of which python in os terminal

which python

Python related stuff in init file

(setq python-python-command "/usr/local/bin/python")
(require 'python-mode)
;; (setq-default py-shell-name "/usr/local/bin/python")
;; (setq  python-shell-interpreter "/usr/local/bin/python")
(setq py-force-py-shell-name-p t)

; switch to the interpreter after executing code
(setq py-shell-switch-buffers-on-execute-p t)
(setq py-switch-buffers-on-execute-p t)
; don't split windows
(setq py-split-windows-on-execute-p nil)
; try to automagically figure out indentation
(setq py-smart-indentation t)
  • 2
    Can you show your init file (python related stuff)? Can you also show the terminal output of the command which python?
    – Nsukami _
    Jun 26, 2015 at 4:21
  • 1
    Is emacs run from the terminal or started as separate application? In the later case you probably need the exec-path-from-init package to set up the correct environment. Jun 26, 2015 at 11:50
  • updated the question. @AndrewSwann It is indeed run as a separate application I will try that. Jun 26, 2015 at 12:40

1 Answer 1


The solution as pointed out by @AndrewSwann was to use the exec-path-from-init package to set up the correct environment. By adding this to the init file the correct path variables are set from the operating system but only on mac os Source

(when (memq window-system '(mac ns))

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