Lee
Lee

Reputation: 524

python version and python sys.path

I have anaconda installed and do not want to use the system python and its modules.

It is supposed that anaconda runs python in independent environment. However,

$ which python
/home/user/anaconda/bin/python

$ python --version
Python 2.7.3

$ ~/anaconda/bin/python --version
Python 2.7.11 :: Anaconda 2.5.0 (64-bit)

As you can see, python is linked to the system python of version 2.7.3, though which indicates that it is pointed to anaconda python.

$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys;
>>> from pprint import pprint as p
>>> p(sys.path)
['',
 '/soft/python/lib/python2.7/site-packages/distribute-0.6.28-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/mock-1.0.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/nose-1.3.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/pyparsing-2.0.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/tornado-3.2-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages/python_dateutil-2.2-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/six-1.6.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/backports.ssl_match_hostname-3.4.0.2-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/diffpy.pdfgui-1.0_r6798_20120508-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/diffpy.utils-1.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/diffpy.pdffit2-1.0_r6773_20111122-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages/diffpy.Structure-1.2-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/diffpy.pdfgetx-1.0_r2152_20130314-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/rasterstats-0.7.0-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/rasterio-0.24.1-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages/Shapely-1.5.9-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages/enum34-1.0.4-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/snuggs-1.3.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/cligj-0.2.0-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/affine-1.2.0-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/click-4.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/progress-1.2-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/matplotlib-1.4.3-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages/h5py-2.5.0-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages',
 '/home/user',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/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/PIL',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7']

It's natural that there are a lot of system path in python path. But for anaconda python,

$ ~/anaconda/bin/python
Python 2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec  6 2015, 18:08:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> 
>>> import sys
>>> from pprint import pprint as p
>>> p(sys.path)
['',
 '/soft/python/lib/python2.7/site-packages/distribute-0.6.28-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/mock-1.0.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/nose-1.3.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/pyparsing-2.0.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/tornado-3.2-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages/python_dateutil-2.2-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/six-1.6.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/backports.ssl_match_hostname-3.4.0.2-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/diffpy.pdfgui-1.0_r6798_20120508-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/diffpy.utils-1.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/diffpy.pdffit2-1.0_r6773_20111122-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages/diffpy.Structure-1.2-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/diffpy.pdfgetx-1.0_r2152_20130314-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/rasterstats-0.7.0-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/rasterio-0.24.1-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages/Shapely-1.5.9-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages/enum34-1.0.4-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/snuggs-1.3.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/cligj-0.2.0-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/affine-1.2.0-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/click-4.1-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/progress-1.2-py2.7.egg',
 '/soft/python/lib/python2.7/site-packages/matplotlib-1.4.3-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages/h5py-2.5.0-py2.7-linux-x86_64.egg',
 '/soft/python/lib/python2.7/site-packages',
 '/home/user',
 '/home/user/anaconda/lib/python27.zip',
 '/home/user/anaconda/lib/python2.7',
 '/home/user/anaconda/lib/python2.7/plat-linux2',
 '/home/user/anaconda/lib/python2.7/lib-tk',
 '/home/user/anaconda/lib/python2.7/lib-old',
 '/home/user/anaconda/lib/python2.7/lib-dynload',
 '/home/user/anaconda/lib/python2.7/site-packages',
 '/home/user/anaconda/lib/python2.7/site-packages/Sphinx-1.3.5-py2.7.egg',
 '/home/user/anaconda/lib/python2.7/site-packages/cryptography-1.0.2-py2.7-linux-x86_64.egg',
 '/home/user/anaconda/lib/python2.7/site-packages/flake8-2.5.1-py2.7.egg',
 '/home/user/anaconda/lib/python2.7/site-packages/mccabe-0.3.1-py2.7.egg',
 '/home/user/anaconda/lib/python2.7/site-packages/setuptools-20.1.1-py2.7.egg']

Still a lot of system path.

If I filter the sys.path by

sys.path = filter(lambda (x): x.startswith('/home/user/anaconda'), sys.path) the python path is clean but there will be a lot of ImportErrors.

I have exported $PYTHONPATH=.

Upvotes: 0

Views: 820

Answers (3)

Kannan Ramaswamy
Kannan Ramaswamy

Reputation: 2521

Did you setup your Conda environment and activate it?

Basically you need to be in a folder where you want to create a project, launch a terminal and setup the Conda environment

conda create -n yourenvname python=x.x anaconda

Here you can choose a name for your environment and setup the python version, anaconda and any other packages you need for this environment. Then Conda will install all those for you and will create the environment.

When you need to use the environment, just activate it by:

activate yourenvname

read more: https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/

Upvotes: 0

jfleach
jfleach

Reputation: 513

If you want to use Python3, create a symlink to Python and pip on Debian-based Linus distributions.

sudo ln -s /usr/bin/python3 /usr/bin/python
sudo ln -s /usr/bin/pip3 /usr/bin/pip

Upvotes: 0

pyrocrasty
pyrocrasty

Reputation: 787

  1. Execute type python to check for aliases (or functions).
  2. Execute hash -r to renew the $PATH hashtable, then try which again.

In general, you're probably better off using type than which, since the former is a shell builtin and has access to the shell's PATH hash table, functions and aliases.

  • If you specifically want to look for an external program (as which does), you can use

    type -p 
    

    In other words, it's a more reliable which.

  • If you want to find all locations of executable commands with a given name, you can use

    type -a
    

Upvotes: 1

Related Questions