PYTHONPATH when calling from ipython
Peter Otten
__peter__ at web.de
Sat May 23 09:25:04 EDT 2015
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")
More information about the Python-list
mailing list