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 -- https://mail.python.org/mailman/listinfo/python-list