From unknown Sat Aug 16 21:11:09 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#13570 <13570@debbugs.gnu.org> To: bug#13570 <13570@debbugs.gnu.org> Subject: Status: 24.2; (python.el) "ValueError: Attempted relative import in non-package" with relative import. Reply-To: bug#13570 <13570@debbugs.gnu.org> Date: Sun, 17 Aug 2025 04:11:09 +0000 retitle 13570 24.2; (python.el) "ValueError: Attempted relative import in n= on-package" with relative import. reassign 13570 emacs submitter 13570 Oleksandr Gavenko severity 13570 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 27 17:40:54 2013 Received: (at submit) by debbugs.gnu.org; 27 Jan 2013 22:40:54 +0000 Received: from localhost ([127.0.0.1]:51740 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TzauE-0001LV-92 for submit@debbugs.gnu.org; Sun, 27 Jan 2013 17:40:54 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50580) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TzauC-0001LO-FT for submit@debbugs.gnu.org; Sun, 27 Jan 2013 17:40:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tzatp-0004Ph-Fz for submit@debbugs.gnu.org; Sun, 27 Jan 2013 17:40:30 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-102.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, T_DKIM_INVALID, USER_IN_WHITELIST autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:39809) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tzatp-0004Pd-CR for submit@debbugs.gnu.org; Sun, 27 Jan 2013 17:40:29 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tzatm-0002aR-Hr for bug-gnu-emacs@gnu.org; Sun, 27 Jan 2013 17:40:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tzatl-0004P0-HB for bug-gnu-emacs@gnu.org; Sun, 27 Jan 2013 17:40:26 -0500 Received: from mail-ea0-f169.google.com ([209.85.215.169]:51710) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tzatl-0004Oo-AR for bug-gnu-emacs@gnu.org; Sun, 27 Jan 2013 17:40:25 -0500 Received: by mail-ea0-f169.google.com with SMTP id d13so942539eaa.28 for ; Sun, 27 Jan 2013 14:40:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:subject:date:message-id:mime-version :content-type; bh=NnHuGfZVf1Ik4cyQ6BWG/fjAPt/zSub9AUQwDwUShrU=; b=tjynhZWTPX5VMkutciV6KQV2q1+LGHwNo+qysywmub/xhg8N8xvT/buqW/+WNkrgOK STBdhJ5GXZG1scwHPOcVKxL+J2WeYDGXP7czGf6di6EyCPH40FTW1WBaC7XToGj4465Y jGyMvIVXwpOJDXQvC8AOqp3kNQv467T6jGCsT8hc2drI3FxYRik5FIeLyXIne+xsiCsm JTuUGlBWprpg7Ca+LoOBJr7X+EK07OcgTKkKJLwFB632TIUwrJiC0sbcgnGBRiLMsklg snJ49IrDLgEHQXfnJngCXJdaZzM4KxLdZz1SvbJj4dfq96wGmACiL/VNzM1pJY7XoNfW /NRg== X-Received: by 10.14.225.72 with SMTP id y48mr44384994eep.46.1359326424266; Sun, 27 Jan 2013 14:40:24 -0800 (PST) Received: from desktop ([37.229.4.200]) by mx.google.com with ESMTPS id o3sm9606512eem.15.2013.01.27.14.40.22 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 27 Jan 2013 14:40:22 -0800 (PST) From: Oleksandr Gavenko To: bug-gnu-emacs@gnu.org Subject: 24.2; (python.el) "ValueError: Attempted relative import in non-package" with relative import. Date: Mon, 28 Jan 2013 00:40:20 +0200 Message-ID: <87a9rup7vv.fsf@gavenkoa.example.com> MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -3.4 (---) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 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: -6.1 (------) In GNU Emacs 24.2.1 (x86_64-pc-linux-gnu, GTK+ Version 3.4.2) of 2013-01-21 on trouble, modified by Debian # mkdir package # cd package # cat <cmd.py from . import lib lib.ok() EOF # cat <lib.py def ok(): print('ok') EOF When you open cmd.py and try C-c C-l (python-load-file) you get: >>> Traceback (most recent call last): Traceback (most recent call last): File "/home/user/devel/tmp/package/cmd.py", line 1, in from . import lib ValueError: Attempted relative import in non-package With C-c C-c (python-send-string) ever worse: it uses (make-temp-file "py") so relative import is not possible!! -- Best regards! From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 28 16:09:24 2013 Received: (at 13570) by debbugs.gnu.org; 28 Jan 2013 21:09:24 +0000 Received: from localhost ([127.0.0.1]:52960 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TzvxD-0003gI-Ez for submit@debbugs.gnu.org; Mon, 28 Jan 2013 16:09:24 -0500 Received: from mail-ee0-f52.google.com ([74.125.83.52]:60998) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TzvxB-0003gA-1n for 13570@debbugs.gnu.org; Mon, 28 Jan 2013 16:09:22 -0500 Received: by mail-ee0-f52.google.com with SMTP id b15so1508162eek.11 for <13570@debbugs.gnu.org>; Mon, 28 Jan 2013 13:08:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:subject:organization:date:message-id :mime-version:content-type; bh=6YWgKqSKXhAfk61TGjE+eDvIDPYPH0LYWwR39USHEZ0=; b=XRp9jXVfFIK9NsvznIu01iVCFAsn8R9sGdq1dyZrPEnZAdIw7wdwToJ2Qap4agXe5N X9HtbI+q+nW0zjY/eWROm1ALVSuMdrPON5TbZY65RgR3u/xEDQqqxZr6H/+ENsRx2AlV NgXqBTqmjo+NLgeu9lLacqjLmlkaOY4V5d4htEt20B0JmfVhxTb6cgZ/ZLhu37SLo7Zj TJnWCcPqA2UlrwNYhI5vcrVWQ1dtIYQmt7qmbhR2w2CtEnG+plbcCMSvV3DGCtoKJGWa Rx/QXeYAE7D1LnMmoV/kv2lDWG9U27q8NSPyMYYHnrb9E9ilhUyl1A9UhQdNFV/Cw1uV 1m5w== X-Received: by 10.14.173.69 with SMTP id u45mr55748617eel.21.1359407333067; Mon, 28 Jan 2013 13:08:53 -0800 (PST) Received: from desktop ([37.229.4.200]) by mx.google.com with ESMTPS id 6sm17514532eea.3.2013.01.28.13.08.49 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 28 Jan 2013 13:08:51 -0800 (PST) From: Oleksandr Gavenko To: 13570@debbugs.gnu.org Subject: [PATCH] 24.2; (python.el) "ValueError: Attempted relative import in non-package" with relative import. Organization: Oleksandr Gavenko , http://gavenkoa.users.sf.net Date: Mon, 28 Jan 2013 23:08:48 +0200 Message-ID: <87txq1ypzz.fsf@gavenkoa.example.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.1 (/) X-Debbugs-Envelope-To: 13570 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 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.6 (--) As I previously wrote python.el on C-c C-l (python-load-file) throw: ValueError: Attempted relative import in non-package if module have relative import, like: from . import module from ..sound import module Seems that 'eimport' from emacs2.py/emacs3.py already support packages. So I improve 'python-load-file' in python.el by locating most top non-package directory, see example: $ mkdir /home/user/pythonpath/package1/package2/ $ touch /home/user/pythonpath/package1/package2/__init__.py $ touch /home/user/pythonpath/package1/__init__.py (defun foo () (let ( (module "module") (path "/home/user/pythonpath/package1/package2/") ) (while (file-exists-p (concat path "__init__.py")) (string-match "\\(.+/\\)\\([^/]+\\)/$" path) (setq module (concat (match-string 2 path) "." module)) (setq path (match-string 1 path)) ) (list path module))) The patch is: --- old/python.el 2013-01-28 22:56:50.000000000 +0200 +++ new/python.el 2013-01-28 22:59:24.000000000 +0200 @@ -1703,8 +1703,12 @@ (python-send-command (if (string-match "\\.py\\'" file-name) (let ((module (file-name-sans-extension - (file-name-nondirectory file-name)))) - (format "emacs.eimport(%S,%S)" - module (file-name-directory file-name))) + (file-name-nondirectory file-name))) + (path (file-name-directory file-name))) + (while (file-exists-p (concat path "__init__.py")) + (string-match "\\(.+/\\)\\([^/]+\\)/$" path) + (setq module (concat (match-string 2 path) "." module)) + (setq path (match-string 1 path))) + (format "emacs.eimport(%S,%S)" module path)) (format "execfile(%S)" file-name))) (message "%s loaded" file-name))) But newer python.el version no longer use emacs2.el. I have no time to compile and debug latest Emacs but suggest use similar technique to allow relative import... -- Best regards! From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 27 02:41:58 2014 Received: (at 13570-done) by debbugs.gnu.org; 27 Jul 2014 06:41:58 +0000 Received: from localhost ([127.0.0.1]:39164 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XBI9e-00032g-6L for submit@debbugs.gnu.org; Sun, 27 Jul 2014 02:41:58 -0400 Received: from fencepost.gnu.org ([208.118.235.10]:51300 ident=Debian-exim) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XBI9b-00032X-0I for 13570-done@debbugs.gnu.org; Sun, 27 Jul 2014 02:41:56 -0400 Received: from 222-99-245-190.fibertel.com.ar ([190.245.99.222]:33432 helo=localhost) by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1XBI9a-0005Lm-71 for 13570-done@debbugs.gnu.org; Sun, 27 Jul 2014 02:41:54 -0400 From: fgallina@gnu.org (=?utf-8?Q?Fabi=C3=A1n?= Ezequiel Gallina) To: 13570-done@debbugs.gnu.org Subject: 24.2; (python.el) "ValueError: Attempted relative import in non-package" with relative import. Date: Sun, 27 Jul 2014 03:41:52 -0300 Message-ID: <87wqaze21b.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 13570-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Fixed at revno 117584 in trunk. The new `python-shell-package-enable' command let's you enable a package for the current shell and use relative imports in evaled code. Cheers, Fabi=C3=A1n From unknown Sat Aug 16 21:11:09 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 24 Aug 2014 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator