Emacs not supporting python?

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

tias42
Posts: 32
Joined: Sun Oct 04, 2009 10:56 am UTC

Emacs not supporting python?

Postby tias42 » Mon Jul 05, 2010 1:04 pm UTC

I have searched thoroughly on the internet (I have spent ALL evening doing this :S) and I cannot find out how to get python working properly in emacs. I have Windows XP and emacs 23.2 and python 2.6.4.

The main problem is that when I try to run the code I've written with C-c C-c I get an error " 'python' is not recognized as an internal or external command, operable program or batch file". Syntax highlighting still works in python mode, though. Basically I get the feeling that the issue is something to do with emacs not knowing where to find all my python files.

I have tried installing a bunch of different stuff, adding my python directory to the load path, adding various commands to the .emacs file, changing python.el for python-mode.el, moving python.exe into the emacs directory...

The most promising thing I tried was (setq py-python-command '("C:/Program Files/Python")), which at the very least changed the error message I was getting to "Wrong type argument: characterp, 'C:/Program Files/Python' "

I know hardly anything about emacs and nothing at all about elisp, so some idiot-proof help would be really appreciated :)

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Emacs not supporting python?

Postby 0xBADFEED » Mon Jul 05, 2010 1:29 pm UTC

The easiest and most typical solution would probably be to just add the python directory to your Windows search path.

tias42
Posts: 32
Joined: Sun Oct 04, 2009 10:56 am UTC

Re: Emacs not supporting python?

Postby tias42 » Mon Jul 05, 2010 1:36 pm UTC

Sorry to be ignorant, but what is the windows search path/ how do I modify it?

jdsnape
Posts: 3
Joined: Tue Apr 07, 2009 3:59 pm UTC

Re: Emacs not supporting python?

Postby jdsnape » Mon Jul 05, 2010 1:46 pm UTC

If you go to "My Computer", right click in empty space and select "Pproperties". Then switch to the advanced tab, a click the "environment variables" button. In the "System Variables" scrollbox you should see one called path, which you can then edit to include the python directory.

tias42
Posts: 32
Joined: Sun Oct 04, 2009 10:56 am UTC

Re: Emacs not supporting python?

Postby tias42 » Mon Jul 05, 2010 6:08 pm UTC

Now when I run the code it says "Fontifying *Python*... (regexps.......)" and apparently is in the middle of some process but never does anything else.

++$_
Mo' Money
Posts: 2370
Joined: Thu Nov 01, 2007 4:06 am UTC

Re: Emacs not supporting python?

Postby ++$_ » Tue Jul 06, 2010 3:31 am UTC

tias42 wrote:Now when I run the code it says "Fontifying *Python*... (regexps.......)" and apparently is in the middle of some process but never does anything else.
What if you interrupt it and turn off font-lock-mode? (Type M-x font-lock-mode)

tias42
Posts: 32
Joined: Sun Oct 04, 2009 10:56 am UTC

Re: Emacs not supporting python?

Postby tias42 » Tue Jul 06, 2010 4:29 am UTC

It doesn't do anything. I tried both turning it off beforehand and turning it off during the process.

troyp
Posts: 557
Joined: Thu May 22, 2008 9:20 pm UTC
Location: Lismore, NSW

Re: Emacs not supporting python?

Postby troyp » Tue Jul 06, 2010 12:57 pm UTC

tias42 wrote:IThe most promising thing I tried was (setq py-python-command '("C:/Program Files/Python")), which at the very least changed the error message I was getting to "Wrong type argument: characterp, 'C:/Program Files/Python' "

When you've set the Python command here, you've only included the path to the executable's folder, not the executable itself. So you need, say, "C:/Program Files/Python/python.exe".
Also, I'm not sure why you've enclosed the value in a list - maybe that's allowed, I'm not sure, but it isn't necessary. So just

Code: Select all

(setq py-python-command  "C:/Program Files/Python/python.exe")
should do it.
Of course, if you've made sure the Python directory is on your path, you should only need

Code: Select all

(setq py-python-command "python")
which I think is the default.

It doesn't do anything. I tried both turning it off beforehand and turning it off during the process.
Are you still using python-mode.el? Try going back to python.el (this is the Python mode usually used with GNU emacs, I think python-mode.el is an obsolete and/or XEmacs mode).
Also, undo anu other changes you've made to your .emacs that may be stuffing things up.

tias42
Posts: 32
Joined: Sun Oct 04, 2009 10:56 am UTC

Re: Emacs not supporting python?

Postby tias42 » Tue Jul 06, 2010 3:26 pm UTC

I previously also tried "C:/Program Files/Python/python.exe". It's in that format (a list, so you have edified me) as several of the suggestions I saw on forums were in that format, and when I didn't it didn't like the space in "program files" and stopped at C:/Program.

I went back to python.el and have reverted all my other changes. Also, I tried using just "python" in the above section after your suggestion but I think it is a different issue now - it ostensibly loads python fine, and python-shell mode works so it can definitely find python and run python commands. It's this (font?) error that I can't remedy.

troyp
Posts: 557
Joined: Thu May 22, 2008 9:20 pm UTC
Location: Lismore, NSW

Re: Emacs not supporting python?

Postby troyp » Tue Jul 06, 2010 10:28 pm UTC

Okay, I've done some googling and I think I've found your problem.
from this thread...
You're right, it does work for me, too. The difference with my
previous test is that I started inferior Python first and loaded the
file after that. In Emacs 22, the file is loaded into the running
inferior Python session, but in 23 a new Python session is
initialized. Silly me did not even notice the second inferior Python
buffer. I tried to use the one I had open in a window, which obviously
didn't get the loaded file. Further C-c C-l commands do the right
thing and load the file into the same running Python session.

So I'd guess you've got two Python processes open at once and the second isn't working. Make sure you close any existing python buffer before you load a file with C-c C-l.
(I'm on emacs 22.3 so I haven't run into this yet - I'll have to keep it in mind when I switch)

tias42
Posts: 32
Joined: Sun Oct 04, 2009 10:56 am UTC

Re: Emacs not supporting python?

Postby tias42 » Wed Jul 07, 2010 4:30 am UTC

Thanks - that wasn't exactly my problem but it helped me find it.

I feel kind of foolish now - my problem was basically that it was working and I just couldn't find the output it was producing. Your suggestion made me actually examine the buffer list and after a bunch of fiddling I figured out that what I had been doing initially actually did exactly what I wanted.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 7 guests