From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jim Blandy Newsgroups: gmane.emacs.bugs Subject: bug#6782: python.el's run-python removes current directory from sys.path Date: Mon, 2 Aug 2010 11:11:48 -0700 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1280865293 9146 80.91.229.12 (3 Aug 2010 19:54:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 3 Aug 2010 19:54:53 +0000 (UTC) To: 6782@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 03 21:54:50 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OgNZG-0006Xs-Bi for geb-bug-gnu-emacs@m.gmane.org; Tue, 03 Aug 2010 21:54:49 +0200 Original-Received: from localhost ([127.0.0.1]:33394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgNZC-0003FR-TW for geb-bug-gnu-emacs@m.gmane.org; Tue, 03 Aug 2010 15:54:26 -0400 Original-Received: from [140.186.70.92] (port=38749 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgIdJ-0003HW-2I for bug-gnu-emacs@gnu.org; Tue, 03 Aug 2010 10:38:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OgIdH-000383-97 for bug-gnu-emacs@gnu.org; Tue, 03 Aug 2010 10:38:20 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:34035) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OgIdH-00037y-5Z for bug-gnu-emacs@gnu.org; Tue, 03 Aug 2010 10:38:19 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1OgIJe-00023s-B4; Tue, 03 Aug 2010 10:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jim Blandy Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 03 Aug 2010 14:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 6782 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.12808450307903 (code B ref -1); Tue, 03 Aug 2010 14:18:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Aug 2010 14:17:10 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OgIIn-00023P-9V for submit@debbugs.gnu.org; Tue, 03 Aug 2010 10:17:09 -0400 Original-Received: from mail.gnu.org ([199.232.76.166] helo=mx10.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OfzU2-0008Pi-SZ for submit@debbugs.gnu.org; Mon, 02 Aug 2010 14:11:32 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:46370) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1OfzUQ-00062g-Cl for submit@debbugs.gnu.org; Mon, 02 Aug 2010 14:11:54 -0400 Original-Received: from [140.186.70.92] (port=39573 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OfzUN-0007YS-UD for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2010 14:11:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OfzUL-0001ne-Uk for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2010 14:11:51 -0400 Original-Received: from mail-qy0-f176.google.com ([209.85.216.176]:57614) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OfzUL-0001nO-Qy for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2010 14:11:49 -0400 Original-Received: by qyk34 with SMTP id 34so1979660qyk.0 for ; Mon, 02 Aug 2010 11:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=F3hKhd4e9/JdgrZQK43iB96vmLTHmUW98+e4H1mXPeg=; b=Hhd8gCGEuSDguC8mBVvywNqn06+n/RG+OqoAMpFqZXbmt6nalIaHtEAbAOtJanKSiE BYxl8sB1FTptNXN0cJtTlcG5A0R+DYoEX9PcW8BQ1FFuo6TZVgwxPeopj5vf8I/68EaH v5erM6VxxDpOWNk34fvG9oUu+sxPFQD9/N0us= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=KFRQNcv3hgEJn+E2jICg6HmN9pFz+LKS18xMUjBKmWg0DMuWDTl4u7tZwLq5+s83Ti Cx+M/B/K1V8fFUhw9mphF5JFpIyutkCEL6MCEkIT2ruDRBWS5Hf/QMvCPbXSVTJ7kHBA hWhfCJjXdiSlHd1fmkZrEcwi9WzjPlqdbYOxs= Original-Received: by 10.224.66.201 with SMTP id o9mr2030753qai.277.1280772708557; Mon, 02 Aug 2010 11:11:48 -0700 (PDT) Original-Received: by 10.229.72.78 with HTTP; Mon, 2 Aug 2010 11:11:48 -0700 (PDT) X-Google-Sender-Auth: MNFgYckGESyDF13tFI3TDbAQWks X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Mailman-Approved-At: Tue, 03 Aug 2010 10:17:08 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Tue, 03 Aug 2010 10:18:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Mailman-Approved-At: Tue, 03 Aug 2010 15:54:21 -0400 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:39215 Archived-At: Please write in English if possible, because the Emacs maintainers usually do not have translators to read other languages for them. Your bug report will be posted to the emacs-pretest-bug@gnu.org mailing list. Please describe exactly what actions triggered the bug and the precise symptoms of the bug: Suppose I have a directory set up as follows: $ ls a.py b.py $ cat a.py import b b.hello() $ cat b.py def hello(): print "Hello!" In most normal ways of running Python, a.py is able to find b.py, even though PYTHONPATH is not set: $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import a Hello! >>> $ python a.py Hello! $ echo $PYTHONPATH $ However, if I visit a.py in Emacs, and then hit `C-c C-c' (python-send-buffer), I get the following error: >>> Traceback (most recent call last): File "/tmp/py6932ha1", line 1, in import b ImportError: No module named b >>> I think the problem is in the way Emacs' python-mode runs Python. If I type M-x run-python, then I see this: >>> import sys >>> '' in sys.path False >>> whereas if I run the python interpreter from the shell, I see: >>> import sys >>> '' in sys.path True >>> This seems to be due to the following code in run-python from progmodes/python.el: (let* ((cmdlist (append (python-args-to-list cmd) '("-i" "-c" "import sys; sys.path.remove('')"))) which has no comment, and the following helpful ChangeLog entry: 2008-08-24 Romain Francoise * progmodes/python.el (run-python): Remove '' from sys.path. Here's a workaround that one can put in one's .emacs file: (defun python-reinstate-current-directory () "When running Python, add the current directory ('') to the head of sys.path. For reasons unexplained, run-python passes arguments to the interpreter that explicitly remove '' from sys.path. This means that, for example, using `python-send-buffer' in a buffer visiting a module's code will fail to find other modules in the same directory. Adding this function to `inferior-python-mode-hook' reinstates the current directory in Python's search path." (python-send-string "sys.path[0:0] = ['']")) (add-hook 'inferior-python-mode-hook 'python-reinstate-current-directory) In GNU Emacs 23.0.91.2 (i686-pc-linux-gnu, GTK+ Version 2.14.4) of 2009-03-20 on frida Windowing system distributor `The X.Org Foundation', version 11.0.10604000 configured using `configure '--prefix=/home/jimb/emacs'' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: nil value of $LC_MESSAGES: nil value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: nil value of $LANG: en_US.UTF-8 value of $XMODIFIERS: nil locale-coding-system: utf-8-unix default-enable-multibyte-characters: t Major mode: Inferior Python Minor modes in effect: compilation-shell-minor-mode: t erc-list-mode: t erc-menu-mode: t erc-autojoin-mode: t erc-ring-mode: t erc-networks-mode: t erc-pcomplete-mode: t erc-track-mode: t erc-track-minor-mode: t erc-match-mode: t erc-button-mode: t erc-fill-mode: t erc-stamp-mode: t erc-netsplit-mode: t erc-irccontrols-mode: t erc-noncommands-mode: t erc-move-to-prompt-mode: t erc-readonly-mode: t tooltip-mode: t mouse-wheel-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t global-auto-composition-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t transient-mark-mode: t Recent input: e s d s e n d - s t r i n g SPC " s y s . p a t h [ : 0 : 0 0 : 0 ] SPC = SPC [ ' ' ] " C-b \ n C-e C-a M-f M-f M-f C-e C-M-b C-M-f ) ( C-a C-k C-M-b C-M-f M-> ) ( a d d - h o o k SPC ' p y t h n o n M-b C-b C-h f C-e M-b i n e f i o r i n f e r i o r - C-e / m o m - h C-h f SPC ' p y t h o n - i r e i M-/ ) C-j C-p C-k C-p C-p C-p C-p C-p C-M-x C-n C-n C-n C-n C-e M-> C-x b * * p P t h y t h C-x k M-x r u n - p y t h s y s . p a t h C-x k M-x r u n - p y t h s y s . p a t h C-x k C-x b a . p C-c C-c C-x o C-x b * P T y C-SPC C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p M-w C-x C-x C-4 C-x C-x C-x M-w M-x r e p o r t - e m a c s - b u g Recent messages: Fontifying *Python*... (regexps...........) Mark set Making completion list...done Type C-x 4 C-o RET to restore the other window. python-reinstate-current-directory Mark set Fontifying *Python*... (regexps...........) Fontifying *Python*... (regexps...........) Fontifying *Python*... (regexps...........) Mark set