3

I do have python3 on my laptop.

$ sudo find / -name "python3" | python3-locations.org

(partial list of locations)

/usr/local/bin/python3

/usr/lib/python3

/usr/share/doc/python3

/usr/share/lintian/overrides/python3

/usr/share/bash-completion/completions/python3

/usr/share/python3

/usr/bin/python3

/etc/python3

When I

$ emacs 25.2.1
C-x C-f foo.py

apparently I enter major mode Python

C-c C-p ; start interpreter

I get:

Python 2.7.15+ (default, Nov 27 2018, 23:36:35) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> python.el: native completion setup loaded
>>>

Process Python finished Python 2.7.15+ (default, Nov 27 2018, 23:36:35) [GCC 7.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> python.el: native completion setup loaded >>>

I expect that I need to add some expression in .emacs.d/init.el. I have done some research into this, and found a recommendation to add this expression

(add-hook 'python-mode-hook #'(lambda () (setq py-python-command "python3")))

to that file. I restarted emecs with no errors, but I still get Python2.7.

What can I do?

dagmarPrime
  • 131
  • 2

2 Answers2

2

With the built-in python.el, you can customize python-shell-interpreter:

(setq python-shell-interpreter "python3")
Kyle Meyer
  • 7,024
  • 27
  • 22
1

Default Python-shell delivered by python-mode.el is called by \C-c ! resp. [(control c)(!)].

The key used called run-python from shipped python.el.

WRT to hook: it should work but only from a buffer in python-mode. When just opening a shell, it might not be run yet and the value not known.

Suggest to set py-python-command by M-x customize-variable... or using simply (setq ...)

If not done, please consider to file a bug-report at https://gitlab.com/python-mode-devs/python-mode/issues

Andreas Röhler
  • 1,886
  • 11
  • 10