Running Python interpreter in Emacs

R

Rex Eastbourne

Hi,

I'm interested in running a Python interpreter in Emacs. I have Python
extensions for Emacs, and my python menu lists "C-c !" as the command
to run the interpreter. Yet when I run it I get the message "Spawning
Child Process: invalid argument." What do I need to do/download to fix
this?

I read in a post in this group from a while back where someone had the
following lines in his .emacs file:

(setq interpreter-mode-alist
(cons '("python" . python-mode)
interpreter-mode-alist))

Does that have something to do with it? Do I have to set my load-path
to my python interpreter?

Thanks,

Rex
 
S

Skip Montanaro

Rex> I'm interested in running a Python interpreter in Emacs. I have
Rex> Python extensions for Emacs, and my python menu lists "C-c !" as
Rex> the command to run the interpreter. Yet when I run it I get the
Rex> message "Spawning Child Process: invalid argument." What do I need
Rex> to do/download to fix this?

Good question. Works fine for me on MacOSX 10.3 w/ XEmacs 21.4.15,
python-mode 4.75 and Python built from CVS. Can you give some details of
your environment?

Rex> I read in a post in this group from a while back where someone had
Rex> the following lines in his .emacs file:

Rex> (setq interpreter-mode-alist
Rex> (cons '("python" . python-mode)
Rex> interpreter-mode-alist))

Rex> Does that have something to do with it?

I doubt it. What's the value of interpreter-mode-alist? I have

'("python" . python-mode)

in my list by default (as a side-effect of running python-mode).

Rex> Do I have to set my load-path to my python interpreter?

No. That's how Emacs finds Emacs Lisp files to load. Make sure the
"python" command resides in a directory on your PATH.

Skip
 
P

Philippe C. Martin

Hi,

this is what I have:

(autoload 'python-mode "python-mode" "Python mode." t)

(setq auto-mode-alist (append '(("\\.\\(py\\)$" .
python-mode)) auto-mode-alist))

Plus, you can always spawn a shell then call your script (if the point is to
have access to the output).

Regards,

Philippe
 
R

Rex Eastbourne

Hi Skip and Philippe. I added the path for Python to PATH, but I still
get the same message (when I try executing the current buffer, I get
the message: "The system cannot find the path specified."

Philippe, I have the above lines of code in my .emacs file.

As for my environment, I'm running Emacs 21.4 on Windows XP.

Thanks a lot!
 
P

Philippe C. Martin

Hi,

Since I'm a Linux user, I went through the following procedure:

I installed emacs 20.7.1 and Python 2.4
I installed python-mode 1.0A into site-lisp
I added c:\python24 to my path

I put this .emacs on c:\ (see further down - I'm sure you don't need half of
it)

And everyhing is working fine: python mode is recognized and Ctr-C-C opens a
*Python Output* buffer with the results from my script:

print 1 ==> 1

Hope that helps,

Regards,


Philippe

*****************************************************************************
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(auto-compression-mode t nil (jka-compr))
'(case-fold-search t)
'(current-language-environment "UTF-8")
'(default-input-method "rfc1345")
'(global-font-lock-mode t nil (font-lock))
'(nil nil t)
'(outline-minor-mode t)
'(pc-select-meta-moves-sexps t)
'(pc-select-selection-keys-only t)
'(pc-selection-mode t t)
'(save-place t nil (saveplace))
'(show-paren-mode t nil (paren))
'(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
'(transient-mark-mode t))

;(mouse-wheel-mode t)


(setq indent-tabs-mode nil)
;;(speedbar)

(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
)


;(setq any mode-customization variables you want here)
(autoload 'visual-basic-mode "visual-basic-mode" "Visual Basic mode." t)
(autoload 'python-mode "python-mode" "Python mode." t)

(setq auto-mode-alist (append '(("\\.\\(py\\)$" .
python-mode)) auto-mode-alist))

(setq auto-mode-alist (append '(("\\.\\(frm\\|bas\\|cls\\)$" .
visual-basic-mode)) auto-mode-alist))


*****************************************************************************
 
R

Rex Eastbourne

I have the following in my .emacs:

(add-to-list 'load-path "C:\Program Files\Python24")

Is that enough? I didn't see anything similar to that in your .emacs
file, so I'm wondering if I'm supposed to add the path to my PATH
elsewhere.

Thanks,

Rex
 
P

Philippe C. Martin

I do not think there is any need to tell emacs where Python is; besides
having python.exe in your Windows $PATH.

Regards,

Philippe
 
R

Rex Eastbourne

I went to My Computer | Properties | Advanced | Environment Variables
and added c:\program files\python24 to both the PYTHONPATH and Path
variables. Still no luck. I don't know whether the path I'm talking
about is the same as the $PATH you referred to, or whether I'm supposed
to put python.exe explicitly somewhere; could someone refer me to a
place where I can read about these things?

Thanks!

Rex
 
P

Philippe C. Martin

Hi,

I was refering to the Windows $PATH which you can modify in the same dialog.
To make sure it's done properly, open a console (cmd.exe) and type python

Regards,

Philippe
 
P

Piet van Oostrum

Rex Eastbourne said:
RE> I went to My Computer | Properties | Advanced | Environment Variables
RE> and added c:\program files\python24 to both the PYTHONPATH and Path
RE> variables. Still no luck. I don't know whether the path I'm talking
RE> about is the same as the $PATH you referred to, or whether I'm supposed
RE> to put python.exe explicitly somewhere; could someone refer me to a
RE> place where I can read about these things?

Is c:\program files\python24 the directory where python.exe is?
You can try two things:
1. Use "c:\program files\python24" in the PATH environment variable, i.e.
with the quotes.
2. Set emacs' variable py-python-command to the location of the python
executable, e.g.
(setq py-python-command "c:\\program files\\python24\\python.exe")
or use customize to set that variable.
 
R

Rex Eastbourne

Yes! Thank you so much! (For some reason, by the way, I had to copy
python.exe to my c:/ directory, since the computer could never find the
path in program files/python24. But when I did that, and used
setq-py-python-command, it worked. I now have python.exe in two
locations.)
 
J

John Machin

Rex said:
Yes! Thank you so much! (For some reason, by the way, I had to copy
python.exe to my c:/ directory,

No, you did _not_ need to copy it there. You did _not_ need to copy it
anywhere. Didn't copying an executable to your root directory [on any
operating system] strike you as being one or more of
unusual/strange/weird/dopey?
since the computer could never find the
path in program files/python24.

Probably because you didn't have quotes around it (needed because of the
space) as advised by another poster.

But when I did that, and used
setq-py-python-command, it worked. I now have python.exe in two
locations.)

The Windows Python installer will by default install Python 2.x in
C:\Python2x

One hopes that defaults are sensibly chosen by sensible people. This
appears to have been the case here.

How did you manage to get your Python installed in C:\Program
Files\Python24?
 
R

Rex Eastbourne

Yes, I knew that copying it to my root was a kludge. But between that
and not having it work, I chose the former. (As you might be able to
tell from my posts, I tried multiple things and was frustrated.) I
tried putting quotes around "c:\program files\python24". It still
didn't work.

I chose to install Python in Program Files. I didn't know it would
cause any problems; I just thought it was good to have all my programs
in the same place. I guess I was wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top