Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail 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; 'importerror:': 0.05; 'python3': 0.05; '[1]:': 0.09; '[2]:': 0.09; '[3]:': 0.09; 'imported.': 0.09; 'importerror': 0.09; 'mkdir': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:\\ 30': 0.09; 'python': 0.11; 'python.': 0.11; 'interpreter': 0.15; '15:25': 0.16; '[4]:': 0.16; 'echo': 0.16; 'invoking': 0.16; 'last)': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:when': 0.16; 'wrote:': 0.16; 'shell': 0.18; '>>>': 0.20; 'variable': 0.20; 'windows': 0.20; 'purposes': 0.20; '"",': 0.22; 'interpret': 0.22; 'problem:': 0.22; "skip:' 40": 0.22; 'bit': 0.23; '2015': 0.23; 'module': 0.23; "python's": 0.23; 'import': 0.24; '(most': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'found.': 0.27; 'command': 0.28; 'cest': 0.29; "skip:' 10": 0.30; 'work.': 0.30; "can't": 0.32; 'similar': 0.32; 'enhanced': 0.33; 'traceback': 0.33; 'this?': 0.34; 'file': 0.34; 'could': 0.35; 'to:addr:python-list': 0.35; 'set.': 0.35; 'skip:. 20': 0.35; 'something': 0.35; 'skip:o 20': 0.35; 'but': 0.36; 'created': 0.36; 'there': 0.36; 'modules': 0.36; 'subject:: ': 0.37; 'instead': 0.38; 'detail': 0.38; 'received:org': 0.38; 'thank': 0.39; 'test': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'system.': 0.39; 'mark': 0.40; 'received:de': 0.40; 'confirm': 0.61; 'more': 0.62; 'introduction': 0.63; 'details': 0.63; 'complete': 0.63; 'you.': 0.64; 'within': 0.64; '>>>>>': 0.66; 'saturday': 0.66; 'cecil': 0.84; 'schreef': 0.84; 'westerhof': 0.84; '\xe2\x80\xa6': 0.84; '2014,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: PYTHONPATH when calling from ipython Date: Sat, 23 May 2015 18:09:01 +0200 Organization: None References: <874mn5qjc8.fsf@Equus.decebal.nl> <87iobjpnt4.fsf@Equus.decebal.nl> <87egm7petb.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p57bd8bd4.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 93 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432397364 news.xs4all.nl 2841 [2001:888:2000:d::a6]:55936 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91139 Cecil Westerhof wrote: > Op Saturday 23 May 2015 15:25 CEST schreef Peter Otten: > >> Cecil Westerhof wrote: >> >>> Op Saturday 23 May 2015 11:12 CEST schreef Mark Lawrence: >>> >>>> On 22/05/2015 06:20, Cecil Westerhof wrote: >>>>> I am looking into using ipython instead of bash. But when I call >>>>> a python program from ipython PYTHONPATH is not set. So >>>>> pythonscripts that need a module through PYTHONPATH will not >>>>> work. >>>>> >>>>> I could do something like: >>>>> !PYTHONPATH=~/Python/PythonLibrary python2 … >>>>> >>>>> But I find that a little bit cumbersome. Is there a better way to >>>>> do it? >>>>> >>>> >>>> What makes you think this? Have you tried:- >>>> >>>>>>> import os >>>>>>> os.environ['PYTHONPATH'] >>>> 'C:\\Users\\Mark\\Documents\\Cash\\Python;C: >> \\Users\\Mark\\Documents\\MyPython' >>>> >>>> That might be from the command line interpreter but it also works >>>> the same from iPython for me on Windows 8.1. >>> >>> That does not change anything. The modules are not found. Also not >>> when using %run. >> >> >> That may be because ~ is not expanded. >> >> Try >> >> os.environ["PYTHONPATH"] = >> os.path.expanduser("~/Python/PythonLibary") > > That is not the problem: > os.environ['PYTHONPATH'] > gives: > .:/home/cecil/Python' > > As I interpret it is that the very handy shell variable is not used in > ipython. > I can't confirm that finding. For test purposes I created foo/bar/hello.py. Then I verified that the hello.py module is not found when invoking the python3 interpreter from within ipython3. Once I update os.environ["PYTHONPATH"] the module is successfully imported. The complete session: $ mkdir -p foo/bar $ echo 'print("hello from foo/bar")' > foo/bar/hello.py $ ipython3 Python 3.4.0 (default, Apr 11 2014, 13:05:11) Type "copyright", "credits" or "license" for more information. IPython 1.2.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: import hello.py --------------------------------------------------------------------------- ImportError Traceback (most recent call last) in () ----> 1 import hello.py ImportError: No module named 'hello' In [2]: import os In [3]: !python3 -c 'import hello' Traceback (most recent call last): File "", line 1, in ImportError: No module named 'hello' In [4]: os.environ["PYTHONPATH"] = "foo/bar" In [5]: !python3 -c 'import hello' hello from foo/bar If that's not what you want please explain in similar detail what you want to achieve and what you actually tried. Thank you.