sys.path[] question

Thomas Jollans tjol at tjol.eu
Sun Oct 29 06:40:45 EDT 2017


On 28/10/17 19:24, ElChino wrote:
> From the Python2.7 snippet in [1], Python2.7 reports that my
> sys.path[] contains:
>   f:\ProgramFiler\Python27\lib\site-packages\pyreadline-2.0-py2.7-win32.egg
> 
> (a .zip-file)
> 
> But I have also a 'f:\ProgramFiler\Python27\lib\site-packages\pyreadline'
> directory. With the complete package AFAICS.
> 
> So my question is where will Python import a 'import pyreadline' from?

Paths are searched in the order they're listed in sys.path.

You can find out where a module is loaded from by checking its __file__
attribute. Run python (in interactive mode) and execute

>>> import pyreadline
>>> pyreadline.__file__

> E.f. if I do a:
>   python -vv
> f:\ProgramFiler\Python27\lib\site-packages\pyreadline\test\test_lineeditor.py
> 
> 
> it shows a:
>   # zipimport: found 89 names in
> F:\ProgramFiler\Python27\lib\site-packages\pyreadline-2.0-py2.7-win32.egg
> But no other references to pyreadline-2.0-py2.7-win32.egg.
> 
> Does that mean that only this .egg is where python imports all pyreadline
> files from? And if so, can I delete
>   'f:\ProgramFiler\Python27\lib\site-packages\pyreadline' ?

This sounds like a fairly high risk of breaking something (presumably
there is some reason the files are where they are) for absolutely no
gain. It's not like it takes up any meaningful amount of space, is it?
Why would you want to?


-- Thomas



More information about the Python-list mailing list