Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91030 > unrolled thread
| Started by | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| First post | 2015-05-22 07:20 +0200 |
| Last post | 2015-05-23 20:14 +0200 |
| Articles | 12 — 4 participants |
Back to article view | Back to comp.lang.python
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
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2015-05-22 07:20 +0200 |
| Subject | PYTHONPATH when calling from ipython |
| Message-ID | <874mn5qjc8.fsf@Equus.decebal.nl> |
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?
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2015-05-23 10:12 +0100 |
| Message-ID | <mailman.268.1432372378.17265.python-list@python.org> |
| In reply to | #91030 |
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. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2015-05-23 12:53 +0200 |
| Message-ID | <87iobjpnt4.fsf@Equus.decebal.nl> |
| In reply to | #91108 |
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. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2015-05-23 15:25 +0200 |
| Message-ID | <mailman.275.1432387517.17265.python-list@python.org> |
| In reply to | #91113 |
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")
[toc] | [prev] | [next] | [standalone]
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2015-05-23 16:08 +0200 |
| Message-ID | <87egm7petb.fsf@Equus.decebal.nl> |
| In reply to | #91126 |
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.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [prev] | [next] | [standalone]
| From | Laura Creighton <lac@openend.se> |
|---|---|
| Date | 2015-05-23 17:00 +0200 |
| Message-ID | <mailman.279.1432393226.17265.python-list@python.org> |
| In reply to | #91134 |
In a message of Sat, 23 May 2015 16:08:00 +0200, Cecil Westerhof writes:
>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.
>
>--
>Cecil Westerhof
>Senior Software Engineer
>LinkedIn: http://www.linkedin.com/in/cecilwesterhof
It's used around here. But we all have to do:
export PYTHONPATH=${PYTHONPATH}:/usr/local/ipython/lib/python
in our .bashrc files -- or whatever you do if you don't use bash
to get things to work with ipython.
Is your problem that you are not getting one particular directory
loaded, or can you not find any modules at all?
Laura
[toc] | [prev] | [next] | [standalone]
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2015-05-23 17:24 +0200 |
| Message-ID | <87a8wvpb9t.fsf@Equus.decebal.nl> |
| In reply to | #91135 |
Op Saturday 23 May 2015 17:00 CEST schreef Laura Creighton:
> In a message of Sat, 23 May 2015 16:08:00 +0200, Cecil Westerhof
> writes:
>> 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.
>>
>> --
>> Cecil Westerhof
>> Senior Software Engineer
>> LinkedIn: http://www.linkedin.com/in/cecilwesterhof
>
> It's used around here. But we all have to do:
> export PYTHONPATH=${PYTHONPATH}:/usr/local/ipython/lib/python
> in our .bashrc files -- or whatever you do if you don't use bash
> to get things to work with ipython.
But I would like to do the same in ipython. Otherwise it is not really
a good idea to switch from bash to ipython.
> Is your problem that you are not getting one particular directory
> loaded, or can you not find any modules at all?
Normal modules are loaded. Only the ones that are found trough
PYTHONPATH are not found.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2015-05-23 18:09 +0200 |
| Message-ID | <mailman.282.1432397364.17265.python-list@python.org> |
| In reply to | #91134 |
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)
<ipython-input-1-d9db4361d25a> in <module>()
----> 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 "<string>", line 1, in <module>
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.
[toc] | [prev] | [next] | [standalone]
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2015-05-23 19:30 +0200 |
| Message-ID | <87617jp5f4.fsf@Equus.decebal.nl> |
| In reply to | #91139 |
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
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2015-05-23 19:13 +0100 |
| Message-ID | <mailman.285.1432404810.17265.python-list@python.org> |
| In reply to | #91145 |
On 23/05/2015 18:30, Cecil Westerhof wrote: > > 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. The latest iPython is 3.1.0. Time to update? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2015-05-23 21:47 +0200 |
| Message-ID | <87wpzznkj3.fsf@Equus.decebal.nl> |
| In reply to | #91146 |
Op Saturday 23 May 2015 20:13 CEST schreef Mark Lawrence: > On 23/05/2015 18:30, Cecil Westerhof wrote: >> >> 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. > > The latest iPython is 3.1.0. Time to update? Maybe. ;-) Strange thing is that ipython (for python 2) uses 3.0.0. This is on openSUSE 13.2. On Debian 8 both use 2.3.0. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [prev] | [next] | [standalone]
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2015-05-23 20:14 +0200 |
| Message-ID | <871ti7p3ev.fsf@Equus.decebal.nl> |
| In reply to | #91145 |
Op Saturday 23 May 2015 19:30 CEST schreef Cecil Westerhof:
> 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.
Well it was my fault again. Linux can run very long before you need to
restart it. I work with screen. Before PYTHONPATH was
.:/home/cecil/Python, but later on I changed it to
.:/home/cecil/Python/PythonLibrary. When starting a new shell, the
bash shell had the right value. But when starting ipython it got the
old value. Importing os is not even necessary:
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]: !python2 postOnTwitter.py --used
python2: can't open file 'postOnTwitter.py': [Errno 2] No such file or directory
In [2]: !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]
Feeling a bit silly at the moment. >:-(
By the way I use python2 because the program uses a library that does
not work with python3.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web