PYTHONPATH order on Ubuntu 14.04
<p>I have two computers running Ubuntu 14.04 server (let's call them A and B). B was initially a 10.04 but it has received two upgrades to 12.04 and 14.04. I do not understand why the python path is different on the two computers.</p>

<p>As you can see on the two paths below, the pip installation path <code>/usr/local/lib/python2.7/dist-packages</code> comes <strong>before</strong> the apt python packages path <code>/usr/lib/python2.7/dist-packages</code> on Ubuntu A, but it comes <strong>after</strong> on Ubuntu B.</p>

<p>This leads to several problems if a python package is installed both via apt and pip. As you can see below, if both <code>python-six</code> apt package and <code>six</code> pip package are installed, they may be two different library versions.</p>

<p>The installation of packages system is not always my choice, but might be some dependencies of other packages that are installed.</p>

<p>This problem could probably be solved with a virtualenv, but for reasons I will not detail, <strong>I cannot use virtualenv</strong> here, and must install pip packages system-wide.</p>

<h2>Ubuntu A</h2>

<pre><code>&gt;&gt;&gt; import sys, six
&gt;&gt;&gt; sys.path
['',
 '/usr/local/bin',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/local/lib/python2.7/dist-packages/IPython/extensions']
&gt;&gt;&gt; six
&lt;module 'six' from '/usr/local/lib/python2.7/dist-packages/six.pyc'&gt;
</code></pre>

<h2>Ubuntu B</h2>

<pre><code>&gt;&gt;&gt; import sys, six
&gt;&gt;&gt; sys.path
['',
 '/usr/local/bin',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/local/lib/python2.7/dist-packages/IPython/extensions']
&gt;&gt;&gt; six
&gt;&gt;&gt; &lt;module 'six' from '/usr/lib/python2.7/dist-packages/six.pyc'&gt;
</code></pre>

<p>For both machines <code>$PATH</code> is the same, and <code>$PYTHONPATH</code> is empty.</p>

<ul>
<li><p>Why are those PYTHONPATHS different?</p></li>
<li><p>How can I fix the pythonpath order in "Ubuntu B" so it will load pip
packages before the system ones, in a system-wide way? Is there a apt package I should reinstall or reconfigure so the
PYTHONPATH would prioritize pip packages ?</p></li>
</ul>

<p>You can set the <code>PYTHONPATH</code> to content of <code>Ubuntu A</code></p>

<pre><code>env PYTHONPATH="/usr/local/bin:/usr/lib/python2.7:/usr/lib/python2.7/plat-x86_64-linux-gnu:..." python
</code></pre>

python ubuntu ubuntu-14.04 pythonpath ubuntu-server