Installing SNooPy2
2024/08/20: With the deprecation of numpy.distutils, the whole packaging system for SNooPy had to be re-worked. I've migrated to setuptools so hopefully that will be "okay" going forward. But this could cause issues if you previously installed using the old distutils.
SNooPy2 has seen a number of changes that were motivated by making the installing process less painful (for you and me!). I have tried to update to the latest and most stable python modules and remove the cruft that was simply too difficult to run on modern operating systems (PGPLOT being the major culprit). You now have 4 options for installing SNooPy:
Installing SNooPy using the Install Script.
Download the install script. Go to a folder where you want to install SNooPy. Then run the following in a terminal:
% bash install-snpy myenv
where myenv can be any name you like (e.g., 'snpy'). Depending on whether you have 'conda' in your path or not, this will install SNooPy into a conda environment or a venv environment named myenv. Then either activate through conda:
% conda activate myenv
or activate the venv virtual environment:
% source activate /path/to/myenv/bin/activate
before you start snpy.
Under the hood, the install script will try to create a virtual environment, install the required dependencies, then download the source code from github and build SNooPy. The advantage here is that the 'update-snpy' script will now be able to pull from github and get the feature enhancements and bug fixes as they are uploaded to the repository. Every now and then, SNooPy will give you a warning message that an update is available.
The script is smart enough to detect if you are already using a virtual environment or conda environment and act accordingly.You should get a friendly message at the end letting you know exactly where SNooPy was installed and how to run it.
Installing SNooPy using pip
Now that SNooPy has a page on PyPI (the Python Cheese Shop), you can use 'pip' to install SNooPy. The pip installer knows how to satisfy dependencies, so it should be as simple as running:
% pip install snpy
However, it is possible to end up with conflicts if SNooPy needs a newer version of a package you already have installed. The other downside is that you will only get updates when I get around to updating PyPI, which I will try to do regularly, but if you want to be able to get the up-to-the-minute changes, consider the next solution below.
Installing SNooPy Yourself From Source
Welcome Jedi. You probably know what you're doing if you're reading this section, but nevertheless, allow me to provide some tips on building SNooPy yourself.
1 - Get a Python Distribution
Most systems come with python pre-installed and you are free to use the system python if you wish, as long as it is version 3.8 or newer. However, there are several other binary distributions that come pre-packaged with many of the scientific modules needed by SNooPy and are therefore less likely to have the installer fail with compile-time errors. For this reason, I highly recommend installing one of these, especially if you are working in Windows or a Mac (whose operating systems by default do not come with all the compilers and tools one typically needs to build software). I recommend conda-forge, which runs on Linux, MacOS, and Windows. I do all my development using the Carnegie Python Distribution (CarPy), so that's also a good choice. See table below for a comparative list of distributions.
Get the distribution of your choice, activate it in your shell (usually running a setup script of some kind). Make sure that when you run "python" on the terminal, you get the correct one. You can check this on Unix-type systems by typing 'which python'. For example:
% which python /Users/cburns/miniforge3/bin/python
This is what you get if you install conda-forge on a Mac.
If you are one of those people who wants to "roll your own" or have some crazy setup where you simply must install the python modules yourself, then there is a list of required modules at the bottom of the page. Go and install those before you go on to the next step (or you can let the bootstrap script try to do it for you).
2- Install C/Fortran Compilers if needed
If some of the software required to run SNooPy2 is missing, the installer will attempt to download and compile it. For this, it will require a C compiler and possibly a Fortran compiler. For Linux systems, simply install the appropriate RPMs. For Mac OS users, see this page for details about how to set up your compilers properly.
3- Download SNooPy Source from Github and Install
In some source location, run the following command to get the latest SNooPy code:
git clone https://github.com/obscode/snpy.git snpy
NOTE: if you have been using the old SVN repository, it will continue to be updated, but it is simply a mirror of the github repository (using the subgit software package).
Now all that's left is to run the setup script as usual:
% cd snpy
% pip install .
4 - Run SNooPy2
The setup script will install the snpy startup script into some default location, hopefully in your path, so starting SNooPy should be as simple as:
% snpy
And that's it. SNooPy should start up. Try plotting some light-curves and make sure that the new plotting engine (matplotlib) works correctly. If you wish to use SNooPy non-interactively (write some scripts that import snpy), then you must run those scripts with the same python that was used to install:
% python my-great-script.py
If you don't use the correct python, then your script will bomb and complain it can't find the snpy module.
5 - Keep Up To Date
Along with the snpy start-up script, there is also a 'update-snpy' script. You can use this to download and install the latest fixes to SNooPy. Every now and then, SNooPy may give you a message at startup that an update is available for download. On rare occasions, the update script itself may need to be updated, in which case you will need to run 'update-snpy' twice (first time updates the update script, second time runs the updated update script).
6 - When Things Go Wrong
I've tried to make this fool-proof, but there are SO many OS/architecture/compiler combinations out there that I can't possible anticipate everything. I'll be happy to help you out if the compiling bombs out, but please please PLEASE try installing one of the binary python distributions mentioned in step 1 for your system. That will get us 95% of the way there! Check out the "compiling SNooPy" section of the FAQ, you might find a solution to your problem there.
Required Modules
Here is a table showing what's needed and if it's available in several popular python distributions. The version in parentheses are the latest versions I got to work. You will need a C compiler and a fortran compiler (gfortran) in order to build certain packages from source. Note: many of these can be installed using setuptools' easy_install script.
Package | CarPy | Conda-forge |
---|---|---|
Python (>3.8) | yes | yes |
iPython (8.25.0) | yes | yes |
Numpy (1.26.4) | yes | yes |
Scipy (1.13.1) | yes | yes |
matplotlib (3.8.4) | yes | yes |
astropy (6.1.0) | yes | yes (via conda) |
scikit-learn (1.5.1) | no | yes (via conda) |
h5py | no | yes (via conda) |
onnxruntime | 1.19.0 | yes (via conda) |
pymysql (1.0.2)* | no | yes (via conda) |
emcee (3.1.6)** | yes | no (use pip) |
* only needed for the CSP internal version of SNooPy (to access our SQL database) or if you want to setup your own SQL database.
** optional. emcee is needed to use the new MCMC fitting functionality.