It says you need python 2.7 (which you already have):
$ python --version
Python 2.7.4
Then it says that you need the numpy package too, version >= 1.4.1:
apt-cache policy python-numpy
python-numpy:
Installed: (none)
Candidate: 1:1.7.1-1ubuntu1
Version table:
1:1.7.1-1ubuntu1 0
500 http://archive.ubuntu.com/ubuntu/ raring/main amd64 Packages
As you can see, I have available numpy version 1.7.1, so lets proceed to install it:
sudo apt-get install python-numpy
Now it says that we need cython, lets check if that package is availabe:
apt-cache policy cython
cython:
Installed: (none)
Candidate: 0.17.4-0ubuntu1
Version table:
0.17.4-0ubuntu1 0
500 http://archive.ubuntu.com/ubuntu/ raring/main amd64 Packages
We have it, we install it:
sudo apt-get install cython
Please, do notice that there are other packages that are dependency that are being installed too.
Oddly enough, we also need the scipy module too:
sudo apt-get install python-scipy
Testing. Open python in a terminal and type the following:
$ python
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> import cython
>>> exit()
The above, has to be without errors. If something went wrong, go up and read the guide again, you forgot/skiped a step.
Downloading the CLASS sources from their page, go to the directory in the terminal, and untar it and make it:
cd where/the/tar/is
tar zxf class_v2.0.2.tar.gz
cd class_v2.0.2
make
Here we will wait until is complete. Once this is done, we go to the python directory and start the magic. Without moving from directories run this:
cd python
python setup.py build
python setup.py install --user
Now we have CLASS installed in our user directory. We should test it!
python
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from classy import Class
>>> exit()
Everything is nice a cozzy until here.
Now the truth time, download monthypython tarball in your code directory:
cd ~
mkdir code
cd code
wget https://www.dropbox.com/s/l7mnhwsktp1m8b5/montepython_v1.2.5.tar.bz2?dl=1 -O montepython_v1.2.5.tar.bz2
tar jxf montepython_v1.2.5.tar.bz2
In the installation instructions are some notes that aren't relevant in this peculiar case (a new install) but it may be important when you update montepython.
This change is important. You remember where you installed CLASS? Now you should tell Monte Python where is that. In my case it is /home/braiam/src/class_v2.0.2/class
, yours may be different. You can use find
to look for it:
find ~ -name class -print
Well, now I modify the default.conf
file using whatever you like (I'll use nano) and modify the root
path, so the complete file will looks like:
# Fill in the relevant path to your personal distribution.
# If you create a new file out of this one, please remember to call
# MontePython.py with the option '-conf my.conf'
# At minimum, this file should contain one line:
# ** path['cosmo'] = path to the cosmological code you are using. Note, if you are
# using a modified version of class, be sure that the path contains the word
# class, otherwise the code might not recognise it.
# If you want to use a data folder different from the one present in the folder
# you are executing the code, please also add:
# ** path['data'] = /path/to/the/other/data/
root = '/home/braiam/src/class_v2.0.2/'
path['cosmo'] = root+'/class/'
Save the file and exit.
Test montepython! If everything was ok, you should be able to run code/MontePython.py --help
in your montepythong directory and everything should run:
~/src/montepython$ code/MontePython.py --help
usage: MontePython.py [-h] [-N number of steps] [-o output folder]
[-p input param file] [-c input cov matrix]
[-j jumping method] [-f jumping factor]
[-conf configuration file] [-chain_number chain number]
[-r restart from chain] [-bf restart from best fit file]
[-info [compute information of desired file [compute information of desired file ...]]]
[-bins desired number of bins, default is 20] [-no_mean]
[-comp comparison folder]
[-extra plot file for custom needs] [-noplot] [-all]
[-ext change extension for the output file]
[-fontsize desired fontsize, default is 15]
[-ticksize desired ticksize, default is 13]
Monte Python, a Monte Carlo code in Python
optional arguments:
-h, --help show this help message and exit
-N number of steps
-o output folder
-p input param file
-c input cov matrix
-j jumping method
-f jumping factor
-conf configuration file
-chain_number chain number
-r restart from chain
-bf restart from best fit file
-info [compute information of desired file [compute information of desired file ...]]
-bins desired number of bins, default is 20
-no_mean
-comp comparison folder
-extra plot file for custom needs
-noplot
-all
-ext change extension for the output file
-fontsize desired fontsize, default is 15
-ticksize desired ticksize, default is 13
Best Answer
PyPI is the Python Package index — repository of python modules.
pip
is used to download and install packages directly from PyPI. PyPI is hosted by Python Software Foundation. It is a specialized package manager that only deals with python packages.apt-get
is used to download and install packages from Ubuntu repositories which are hosted by Canonical.Some of the differences between installing python packages from
apt-get
andpip
are as follows:Canonical only provides packages for selected python modules. Whereas, PyPI hosts a much broader range of python modules. So, there are a lot of python modules which you won't be able to install using
apt-get
.Canonical only hosts a single version of any package (generally the latest or the one released in recent past). So, with
apt-get
we cannot decide the version of python-package that we want.pip
helps us in this situation. We can install any version of the package that has previously been uploaded on PyPI. This is extremely helpful in case of conflict in dependencies.apt-get
installs python modules in system-wide location. We cannot just install modules in our project virtualenv.pip
solves this problem for us. If we are usingpip
after activating the virtualenv, it is intelligent enough to only install the modules in our project virtualenv. As mentioned in previous point, if there is a version of a particular python package already installed in system-wide location, and one of our project requires an older version of the same python package, in such situations we can use virtualenv and pip to install that older version of python package without any conflicts.As @Radu Rădeanu pointed out in this answer, there would generally be difference in names of packages as well. Canonical usually names Python 2 packages as
python-<package_name>
and Python 3 packages aspython3-<package_name>
. Whereas forpip
we generally just need to use<package_name>
for both Python 2 as well as Python3 packages.Which one should you use:
Both
apt-get
andpip
are mature package managers which automatically install any other package dependency while installing. You may use anyone as you like. However, if you need to install a particular version of python-package, or install the package in a virtualenv, or install a package which is only hosted on PyPI; onlypip
would help you solve that issue. Otherwise, if you don't mind installing the packages in system-wide location it doesn't really matter whether you useapt-get
orpip
.