Running Python interpreter in Emacs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rex Eastbourne

    Running Python interpreter in Emacs

    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

  • Skip Montanaro

    #2
    Re: Running Python interpreter in Emacs


    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

    Comment

    • Philippe C. Martin

      #3
      Re: Running Python interpreter in Emacs

      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:
      [color=blue]
      > 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[/color]

      Comment

      • Rex Eastbourne

        #4
        Re: Running Python interpreter in Emacs

        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!

        Comment

        • Philippe C. Martin

          #5
          Re: Running Python interpreter in Emacs

          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:
          [color=blue]
          > 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![/color]

          Comment

          • Rex Eastbourne

            #6
            Re: Running Python interpreter in Emacs

            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

            Comment

            • Philippe C. Martin

              #7
              Re: Running Python interpreter in Emacs

              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:
              [color=blue]
              > 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[/color]

              Comment

              • Rex Eastbourne

                #8
                Re: Running Python interpreter in Emacs

                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

                Comment

                • Philippe C. Martin

                  #9
                  Re: Running Python interpreter in Emacs

                  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:
                  [color=blue]
                  > 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[/color]

                  Comment

                  • Piet van Oostrum

                    #10
                    Re: Running Python interpreter in Emacs

                    >>>>> "Rex Eastbourne" <rex.eastbourne @gmail.com> (RE) wrote:
                    [color=blue]
                    >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?[/color]

                    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:\\progra m files\\python24 \\python.exe")
                    or use customize to set that variable.
                    --
                    Piet van Oostrum <piet@cs.uu.n l>
                    URL: http://www.cs.uu.nl/~piet [PGP E17999C4]
                    Private email: piet@vanoostrum .org

                    Comment

                    • Rex Eastbourne

                      #11
                      Re: Running Python interpreter in Emacs

                      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.)

                      Comment

                      • John Machin

                        #12
                        Re: Running Python interpreter in Emacs

                        Rex Eastbourne wrote:[color=blue]
                        > Yes! Thank you so much! (For some reason, by the way, I had to copy
                        > python.exe to my c:/ directory,[/color]

                        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?
                        [color=blue]
                        > since the computer could never find the
                        > path in program files/python24.[/color]

                        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[color=blue]
                        > setq-py-python-command, it worked. I now have python.exe in two
                        > locations.)
                        >[/color]

                        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?

                        Comment

                        • Rex Eastbourne

                          #13
                          Re: Running Python interpreter in Emacs

                          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.

                          Comment

                          Working...