From unknown Wed Aug 20 05:15:36 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6782: python.el's run-python removes current directory from sys.path 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: To: 6782@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.12808450307903 (code B ref -1); Tue, 03 Aug 2010 14:18:02 +0000 Received: (at submit) by debbugs.gnu.org; 3 Aug 2010 14:17:10 +0000 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 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 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 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 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID,T_TO_NO_BRKTS_FREEMAIL autolearn=unavailable version=3.3.1 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 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 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= MIME-Version: 1.0 Received: by 10.224.66.201 with SMTP id o9mr2030753qai.277.1280772708557; Mon, 02 Aug 2010 11:11:48 -0700 (PDT) Received: by 10.229.72.78 with HTTP; Mon, 2 Aug 2010 11:11:48 -0700 (PDT) Date: Mon, 2 Aug 2010 11:11:48 -0700 X-Google-Sender-Auth: MNFgYckGESyDF13tFI3TDbAQWks Message-ID: From: Jim Blandy Content-Type: text/plain; charset=ISO-8859-1 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-Spam-Score: -5.9 (-----) 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 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) 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 From debbugs-submit-bounces@debbugs.gnu.org Sat Nov 20 20:29:15 2010 Received: (at control) by debbugs.gnu.org; 21 Nov 2010 01:29:15 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PJyjz-0007pU-0d for submit@debbugs.gnu.org; Sat, 20 Nov 2010 20:29:15 -0500 Received: from fencepost.gnu.org ([140.186.70.10]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PJyjx-0007pP-B5 for control@debbugs.gnu.org; Sat, 20 Nov 2010 20:29:13 -0500 Received: from localhost ([127.0.0.1]:45375) by fencepost.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PJyow-0005Ju-VJ; Sat, 20 Nov 2010 20:34:23 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <19688.30494.413262.760476@fencepost.gnu.org> Date: Sat, 20 Nov 2010 20:34:22 -0500 From: Glenn Morris To: control Subject: control X-Attribution: GM X-Mailer: VM (www.wonderworks.com/vm), GNU Emacs (www.gnu.org/software/emacs) X-Hue: green X-Ran: "iv_=[L0J%mp6d:G\WSq`{l>G#AS6K8k$IZFiGOn*.d#xJ@'ZykOc-],l2yLa&.F\|`|DY X-Debbugs-No-Ack: yes X-Spam-Score: -5.2 (-----) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.2 (-----) merge 6782 7454 From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 21 11:48:51 2010 Received: (at control) by debbugs.gnu.org; 21 Nov 2010 16:48:51 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PKD5v-0000Xi-Ii for submit@debbugs.gnu.org; Sun, 21 Nov 2010 11:48:51 -0500 Received: from pantheon-po41.its.yale.edu ([130.132.50.98]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PKD5u-0000Xc-2Y for control@debbugs.gnu.org; Sun, 21 Nov 2010 11:48:50 -0500 Received: from furball (dhcp128036226124.central.yale.edu [128.36.226.124]) (authenticated bits=0) by pantheon-po41.its.yale.edu (8.12.11.20060308/8.12.11) with ESMTP id oALGs3iX023726 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sun, 21 Nov 2010 11:54:03 -0500 Received: by furball (Postfix, from userid 1000) id 19E42160AD9; Sun, 21 Nov 2010 11:54:03 -0500 (EST) From: Chong Yidong To: control@debbugs.gnu.org Subject: close 7454 Date: Sun, 21 Nov 2010 11:54:02 -0500 Message-ID: <87bp5ivcr9.fsf@stupidchicken.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-YaleITSMailFilter: Version 1.2c (attachment(s) not renamed) X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) close 7454 thanks