By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,931 Members | 2,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,931 IT Pros & Developers. It's quick & easy.

Running Python interpreter in Emacs

P: n/a
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

Jul 19 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a

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
Jul 19 '05 #2

P: n/a
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

Rex Eastbourne wrote:
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


Jul 19 '05 #3

P: n/a
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!

Jul 19 '05 #4

P: n/a
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))
************************************************** ***************************

Rex Eastbourne wrote:
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!


Jul 19 '05 #5

P: n/a
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

Jul 19 '05 #6

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

Regards,

Philippe


Rex Eastbourne wrote:
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


Jul 19 '05 #7

P: n/a
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

Jul 19 '05 #8

P: n/a
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
Rex Eastbourne wrote:
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


Jul 19 '05 #9

P: n/a
>>>>> "Rex Eastbourne" <re************@gmail.com> (RE) wrote:
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.
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP E17999C4]
Private email: pi**@vanoostrum.org
Jul 19 '05 #10

P: n/a
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.)

Jul 19 '05 #11

P: n/a
Rex Eastbourne wrote:
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?
Jul 19 '05 #12

P: n/a
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.

Jul 19 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.