How can I import a different version of a python module?
<p>I need to run my python script under sklearn v0.17 and on the server they have sklearn v0.15 installed.</p>

<p>So I downloaded the <code>scikit-learn-0.17</code> package into <code>/home/mydir/lib/python2.7/site-packages/</code> and installed the package.</p>

<p>However when I goto other directories and tried to run python and <code>import sklearn</code> the version is still 0.15.</p>

<p>I created <code>~/.startup.py</code> and put the following code</p>

<pre><code>import sys  
sys.path.insert(0,"/home/mydir/lib/Python2.7/site-packages/")
</code></pre>

<p>then I pointed to <code>~/.startup.py</code> in <code>~/.bashrc</code> with </p>

<pre><code>PYTHONSTARTUP=~/.startup.py
</code></pre>

<p>But it does not help.</p>

<p>I am wondering how to fix this. Thank you!</p>

<p>The following files/dirs are in <code>site-packages/</code></p>

<pre><code>easy-install.pth              scikit-learn-0.17         site.pyc
pysam-0.9.1.4                 scikit_learn-0.17-py2.7.egg-info  site.pyo
pysam-0.9.1.4-py2.7-linux-x86_64.egg  site.py               sklearn
</code></pre>

<p>General advice here would be to use <a href="https://virtualenv.pypa.io/en/stable/" rel="nofollow">virtualenv</a>, it allows you to have isolated environments for all your python projects.</p>

<p>So each of your project can use different scikit version. </p>

<p>Tutorial: <a href="https://www.sitepoint.com/virtual-environments-python-made-easy/" rel="nofollow">https://www.sitepoint.com/virtual-environments-python-made-easy/</a></p>

python python-2.7 scikit-learn python-module