Skip to content

Category: Python

which python on which host?

we checked all 3 machines for which version of python on each

literally typing
‘which python’
gives me (at least on  all three hosts) /usr/bin/python      this is not super helpful because it doesnt say which version.

ls -als /usr/bin/python on all three hosts  is also not that helpful as it just spits back the python executable named python.

ls -als /usr/bin | grep python gives me every file in there with a name including python. Then I see that “python” and python2.6 have identical size and date on all three hosts

so the final answer is that all three are using 2.6 by default

Caution: Note that astropy is only on python 2.7 and so we should actually use 2.7  . Yuping  and/or Bruce installed 2.7 in order to “make” psrchive  .  (See Yuping’s post under “python” category.)

python how to find installed astropy: 2.7. Execute .py with “python2.7

The following red material is the newest guidance:
Note that since astropy is in 2.7, 2.7 should really be the default, not 2.6 as it now is. 
To run 2.7 on a program sitting in a file called “nameOfThisFile”,  Type:
“python2.7 nameOfThisFile” in command line, as Helen did in comments atop her IonRMdailyPlot.py  , which is in
/data/psrdata/usr5/rmiono/ionFR-Sobey/

Helen Du figured out the following for finding where (if) astropy is on our network:

/usr/local/lib/python2.7/site-packages (Joel changes this to 2.6 but that doesnt work. see helen’s and Joel’s update at bottom. Esp very top in red)
is where all the packages are.
Specifically, “David Hollander” pointed me to the right path. Here’s what he said:

For Ubuntu,

python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

…is not correct.

It will point you to /usr/lib/pythonX.X/dist-packages

This folder only contains packages your operating system has automatically installed for programs to run.

On ubuntu, the site-packages folder that contains packages installed via setup_tools\easy_install\pip will be in /usr/local/lib/pythonX.X/dist-packages

The second folder is probably the more useful one if the use case is related to installation or reading source code.

If you do not use Ubuntu, you are probably safe copy-pasting the first code box into the terminal.

—————————————————————————–
additional information added by Helen shortly after the above:
Another note:
/usr/lib/python2.6/site-packages  seems to be where the packages that have the basic/initial/…(can’t think of the correct word…) packages for running Python 2.6,
while
/usr/lib64/python2.6/site-packages  has other stuff as well… including scipy, numpy, and matplotlib.

building python 2.7 & related stuff on astronet

Yuping:

references:

https://www.digitalocean.com/community/tutorials/how-to-set-up-python-2-7-6-and-3-3-3-on-centos-6-4

https://www.digitalocean.com/community/tutorials/common-python-tools-using-virtualenv-installing-with-pip-and-managing-packages

——————————————————–

I decided for now to install python 2.7 instead of python 3.0  because that’s what most astronomy python libraries are compatible with (e.g. psrchive). If someone wants to build python 3.0 just substitute the following 2.7.12 with 3.0.* and that should work. Note that I install it in /usr/local/ for each of the computers (i’m not sure what exactly willhappen if multiple hosts try to run the same python) so the following is repeated for each computer we have.

——————————————————

prereqs: make sure you do

sudo yum install tcl tcl-devel tk tk-devel

and check to make sure that all prereqs specified in

https://www.digitalocean.com/community/tutorials/common-python-tools-using-virtualenv-installing-with-pip-and-managing-packages

are satisfied.


install:

First download python from https://www.python.org/ and untar it

>xz -d Python-2.7.12.tar.xz

>tar -xvf Python-2.7.6.tar
>sudo cp -r Python-2.7.6 /usr/local/src/

now we can cd into /usr/local/src/Python-2.7.6 and run

>sudo ./configure --prefix=/usr/local
>sudo make

make will complain about not having the following

>Python build finished, but the necessary bits to build these modules were not found:
>bsddb185           dl                 imageop
>sunaudiodev

These four we can live without (see http://www.kelvinwong.ca/2010/08/02/python-2-7-on-dreamhost/) but if you are missing more than that, google it up.

Now do the following (altinstall is very important otherwise you are gonna break CentOS)

> sudo make altinstall

Now python should be built with executable under /usr/local/bin/python2.7


Now build pip which does package management and virtualenv which lets
you install python library without sudo-ing and makes complicated
dependencies easier to handle (see reference article 2)

 

First you need setuptool because pip depends on it

You can download it from https://pypi.python.org/packages/source/s/setuptools/, untar it and copy it over to /usr/local/src/

then do

> cd setuptools-1.4.2

> sudo /usr/local/bin/python2.7 setup.py install

then you download pip from https://bootstrap.pypa.io/get-pip.py into /usr/local/src/ and do

> sudo /usr/local/bin/python2.7 get-pip.py

and pip should be installed.

Finally you can do the following to get some common libraries installed:

> sudo /usr/local/bin/pip2.7 install numpy scipy matplotlib astropy ipython

you can do this on a single computer, go to some nfs mounted directory (e.g. your home directory) and do

> /usr/local/pip freeze > package_list.txt

which pipes the current installed packages to the file package_list.txt. Then you can hop (ssh) onto other computers and just do

> sudo /usr/local/bin/pip2.7 install -r package_list.txt

And done!

more to come on installing python libraries without being sudo.