Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91145
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: PYTHONPATH when calling from ipython |
| Organization | Decebal Computing |
| References | (1 earlier) <mailman.268.1432372378.17265.python-list@python.org> <87iobjpnt4.fsf@Equus.decebal.nl> <mailman.275.1432387517.17265.python-list@python.org> <87egm7petb.fsf@Equus.decebal.nl> <mailman.282.1432397364.17265.python-list@python.org> |
| Date | 2015-05-23 19:30 +0200 |
| Message-ID | <87617jp5f4.fsf@Equus.decebal.nl> (permalink) |
Op Saturday 23 May 2015 18:09 CEST schreef Peter Otten:
> 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:
I should have checked better. I think I found a bug that made it look
like PYTHONPATH does not work.
In bash I give:
echo $PYTHONPATH
this gives:
.:/home/cecil/Python/PythonLibrary
Then I start ipython3 and get/do the following:
Python 3.4.1 (default, May 23 2014, 17:48:28) [GCC]
Type "copyright", "credits" or "license" for more information.
IPython 2.2.0 -- 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 os
In [2]: os.environ['PYTHONPATH']
Out[2]: '.:/home/cecil/Python'
And PYTHONPATH has a different value. That is why my module is not
found.
When I set PYTHONPATH to the correct value, everything works as
expected:
In [3]: os.environ['PYTHONPATH'] = '.:/home/cecil/Python/PythonLibrary/'
In [4]: !python2 postOnTwitter.py --used
Citation has 50 saved messages of 126:
[6, 55, 43, 82, 28, 116, 2, 50, 100, 5, 0, 122, 75, 51, 121, 60, 114, 13, 102, 78, 31, 107, 73, 109, 54, 119, 72, 90, 89, 113, 118, 41, 11, 27, 48, 77, 19, 111, 62, 98, 110, 9, 10, 115, 63, 15, 53, 101, 94, 92]
Tips has 30 saved messages of 94:
[20, 37, 7, 59, 45, 49, 40, 87, 79, 78, 31, 14, 15, 25, 84, 18, 91, 53, 8, 35, 80, 92, 34, 42, 74, 69, 64, 22, 86, 62]
That begs the question: what is the reason for the corruption of
PYTHONPATH?
I already answered it partly myself. When I change PYTHONPATH in bash
and call ipython3 again, it has the same value as before, so it does
not take its value from the calling bash as I would expect.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
PYTHONPATH when calling from ipython Cecil Westerhof <Cecil@decebal.nl> - 2015-05-22 07:20 +0200
Re: PYTHONPATH when calling from ipython Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-23 10:12 +0100
Re: PYTHONPATH when calling from ipython Cecil Westerhof <Cecil@decebal.nl> - 2015-05-23 12:53 +0200
Re: PYTHONPATH when calling from ipython Peter Otten <__peter__@web.de> - 2015-05-23 15:25 +0200
Re: PYTHONPATH when calling from ipython Cecil Westerhof <Cecil@decebal.nl> - 2015-05-23 16:08 +0200
Re: PYTHONPATH when calling from ipython Laura Creighton <lac@openend.se> - 2015-05-23 17:00 +0200
Re: PYTHONPATH when calling from ipython Cecil Westerhof <Cecil@decebal.nl> - 2015-05-23 17:24 +0200
Re: PYTHONPATH when calling from ipython Peter Otten <__peter__@web.de> - 2015-05-23 18:09 +0200
Re: PYTHONPATH when calling from ipython Cecil Westerhof <Cecil@decebal.nl> - 2015-05-23 19:30 +0200
Re: PYTHONPATH when calling from ipython Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-23 19:13 +0100
Re: PYTHONPATH when calling from ipython Cecil Westerhof <Cecil@decebal.nl> - 2015-05-23 21:47 +0200
Re: PYTHONPATH when calling from ipython Cecil Westerhof <Cecil@decebal.nl> - 2015-05-23 20:14 +0200
csiph-web