Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: Question about imports and packages Date: Tue, 24 May 2016 23:36:37 -0400 Lines: 24 Message-ID: References: <5744f9b1$0$1603$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de PKjZOZwc/UKhzMtHTkGm/AbFYbCo+DUgs4JyM6IlaIPQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Question': 0.05; 'correct.': 0.07; '"python"': 0.09; 'imported': 0.09; 'imports': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python.': 0.11; 'jan': 0.11; 'wed,': 0.15; 'importing': 0.15; '+--': 0.16; '2016': 0.16; '__init__.py': 0.16; 'modules,': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'wrote:': 0.16; 'directory.': 0.18; 'runs': 0.18; 'extension': 0.20; 'work,': 0.21; 'setup,': 0.22; 'file.': 0.22; 'am,': 0.23; 'absolute': 0.23; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; "skip:' 10": 0.28; 'class': 0.33; "d'aprano": 0.33; 'particular,': 0.33; 'steven': 0.33; 'similar': 0.33; 'file': 0.34; 'except': 0.34; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'files': 0.38; 'to:addr:python.org': 0.40; 'your': 0.60; 'received:96': 0.63; 'within': 0.64; '9:02': 0.84; 'received:fios.verizon.net': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-96-227-207-81.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 In-Reply-To: <5744f9b1$0$1603$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <5744f9b1$0$1603$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:109099 On 5/24/2016 9:02 PM, Steven D'Aprano wrote: > On Wed, 25 May 2016 09:35 am, Gerald Britton wrote: > > For brevity, here's your package setup: > > > testpkg/ > +-- __init__.py > +-- testimport.py which runs "from testpkg.testimported import A" > +-- testimported.py containing class A > > Your package layout is correct. But: I have a similar setup, except with multiple files importing from imported file. One way to make absolute imports within a package work, and how I do it, is to put the directory containing testpkg in a .pth file in the site-modules directory. In particular, I have python.pth containing "F:/Python". This effectively makes "Python" an extension of 'site-packages', so when site-packages is searched for modules, so is Python. -- Terry Jan Reedy