On Wed, Feb 01, 2017 at 08:22:43AM -0800, Ben Pfaff wrote:
> On Wed, Feb 01, 2017 at 09:45:56AM -0500, Robert Wojciechowicz wrote:
> > On Tue, Jan 31, 2017 at 03:45:48PM -0800, Ben Pfaff wrote:
> > > OK, so looking closer...
> > > 
> > > The OVS build process runs a few Python programs using syntax like this:
> > >         PYTHONPATH=$(srcdir)/python:$(PYTHONPATH) python program.py
> > > 
> > > This means that sys.path ends up looking like:
> > > 
> > > ['/dir/for/program.py', ..., '/usr/lib/python2.7/dist-packages', ...
> > >  '$(srcdir)/python', ...]
> > 
> > Not really, sys.path is initialized by current working dir, PYTHONPATH 
> > and then followed by installation-dependent default paths.
> 
> You make it sound like I'm making this up!  But my remarks were based on

No, I just wanted to explain that if there is a clean python installation
and PYTHONPATH variable defined the search order is clearly defined.
Unfortunately in real life there are also other things involved,
which may be exisiting in the system or not. For instance there are
so called python path files (.pth), which can modify sys.path also.
Some package installation installation tools (e.g. easy_install)
create such files and then it is hard to make sure in what order
packages will be searched.

> observation.  Here's a simple example:
> 
>     blp@sigabrt:~/nicira/ovs/_build(0)$ PYTHONPATH=$PWD/python python
>     Python 2.7.13 (default, Dec 18 2016, 20:19:42) 
>     [GCC 6.2.1 20161215] on linux2
>     Type "help", "copyright", "credits" or "license" for more information.
>     >>> import sys
>     >>> print sys.path
>     ['',
>     '/home/blp/.local/lib/python2.7/site-packages/p4_hlir-0.9.30-py2.7.egg',
>     '/usr/lib/python2.7/dist-packages',
>     
> '/home/blp/.local/lib/python2.7/site-packages/p4c_behavioral-0.9.4-py2.7.egg',
>     
> '/usr/local/lib/python2.7/dist-packages/PyYAML-3.11-py2.7-linux-x86_64.egg',
>     '/home/blp/.local/lib/python2.7/site-packages/protobuf-3.0.0b3-py2.7.egg',
>     '/home/blp/nicira/ovs/_build/python', '/usr/lib/python2.7',
>     '/usr/lib/python2.7/plat-i386-linux-gnu',
>     '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
>     '/usr/lib/python2.7/lib-dynload',
>     '/home/blp/.local/lib/python2.7/site-packages',
>     '/usr/local/lib/python2.7/dist-packages',
>     '/usr/lib/python2.7/dist-packages/PILcompat',
>     '/usr/lib/python2.7/dist-packages/gtk-2.0',
>     '/usr/lib/pymodules/python2.7']
>     >>> 
> 
> As you can see, /usr/lib/python2.7/dist-packages is well ahead of
> /home/blp/nicira/ovs/_build/python.
> 
> Why does your Python act different from mine in this respect?

Maybe you have used `easy_install` for installation of additional
packages. Unfortunately easy_install creates `easy-install.pth` file,
which modifies sys.path. 

$ virtualenv python27
New python executable in python27/bin/python
Installing setuptools, pip...done.
$ source ~/python27/bin/activate
$ python -c "import sys; print '\n'.join(sys.path)"

/home/rwojciex/python27/lib64/python27.zip
/home/rwojciex/python27/lib64/python2.7
/home/rwojciex/python27/lib64/python2.7/plat-linux2
/home/rwojciex/python27/lib64/python2.7/lib-tk
/home/rwojciex/python27/lib64/python2.7/lib-old
/home/rwojciex/python27/lib64/python2.7/lib-dynload
/usr/lib64/python2.7
/usr/lib/python2.7
/usr/lib64/python2.7/lib-tk
/home/rwojciex/python27/lib/python2.7/site-packages
$ easy_install pyyaml
[...]
$ python -c "import sys; print '\n'.join(sys.path)"

/home/rwojciex/python27/lib/python2.7/site-packages/PyYAML-3.12-py2.7-linux-x86_64.egg
/home/rwojciex/python27/lib64/python27.zip
/home/rwojciex/python27/lib64/python2.7
/home/rwojciex/python27/lib64/python2.7/plat-linux2
/home/rwojciex/python27/lib64/python2.7/lib-tk
/home/rwojciex/python27/lib64/python2.7/lib-old
/home/rwojciex/python27/lib64/python2.7/lib-dynload
/usr/lib64/python2.7
/usr/lib/python2.7
/usr/lib64/python2.7/lib-tk
/home/rwojciex/python27/lib/python2.7/site-packages

Basically those .pth files can be created by other tools also. I moved from 
`easy_install`
to `pip`, because `pip` does not mess up with paths in such strange way.

HTH,
Robert
_______________________________________________
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss

Reply via email to