The installation of glafic

Installation of Glafic Library

The Glafic library is written in C and cannot be directly installed using pip install. However, the author has provided Python bindings via C-to-Python translation. Installation requires a series of steps:

Download Glafic

  1. Download the zip file from Glafic GitHub Repository.
  2. Extract the zip file to a specified directory (any location).
  3. Open a terminal in the corresponding folder.

Install Required Header Files (needed by Glafic library)

Open the terminal and install the necessary dependencies:

1
2
3
4
sudo apt-get update
sudo apt-get install libfftw3-dev
sudo apt-get install libcfitsio-dev
sudo apt-get install libgsl-dev

Locate the Installation Paths for Libraries

The default location is usually /usr/lib, but sometimes the libraries might be installed in different directories. For example, the libraries may be located in /usr/lib/x86_64-linux-gnu. To find the exact location, use the following commands:

1
2
3
sudo find / -name "libcfitsio.so"
sudo find / -name "libfftw3.so"
sudo find / -name "libgsl.so"

The results may look like:

1
2
3
4
5
6
(base) usr@usr-computer:~$ sudo find / -name "libcfitsio.so"
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied
find: ‘/proc/1730/task/1730/net’: Invalid argument
find: ‘/proc/1730/net’: Invalid argument
/usr/lib/x86_64-linux-gnu/libcfitsio.so

Modify Global Environment

Edit your global environment settings to add the library paths:

1
nano ~/.bashrc

Add the following line at the end of the file:

1
export LD_LIBRARY_PATH=/usr/local/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH

Replace /usr/local/lib/x86_64-linux-gnu with the actual path where the libraries are installed.

To save and exit the nano editor:

  • Press Ctrl + O to save.
  • Press Enter to confirm.
  • Press Ctrl + X to exit.

Update the environment:

1
source ~/.bashrc

Modify the Makefile

Edit the Makefile to ensure it uses the correct library paths:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)

ifeq ($(UNAME_S),Darwin)
ifeq ($(UNAME_M),x86_64)
CFLAGS2 = -lcurl
LIBPATH = /usr/local/lib
INCPATH = /usr/local/include
PY_LIBS = -lm -lcfitsio -lfftw3 -lgsl -lgslcblas
else
CFLAGS2 = -lcurl -lz
LIBPATH = /opt/homebrew/lib
INCPATH = /opt/homebrew/include
PY_LIBS = -lm -lcfitsio -lfftw3 -lgsl -lgslcblas
endif
else
ifeq ($(UNAME_S),Linux)
CFLAGS2 =
LIBPATH = /usr/lib/x86_64-linux-gnu # Update this path
INCPATH = /usr/local/include
PY_LIBS = -lm -lcfitsio -lfftw3 -lgsl -lgslcblas # Use dynamic linking (.so)
else
CFLAGS2 =
LIBPATH =
INCPATH =
PY_LIBS =
endif
endif

CC = gcc
CFLAGS = -O2 -Wall -fPIC -I$(INCPATH)
LIBS = -lm -lcfitsio -lfftw3 -lgsl -lgslcblas # Modify to use dynamic libraries (.so)

# Use .so files
LIBS = -lm -L$(LIBPATH) -lcfitsio -lfftw3 -lgsl -lgslcblas # Add -L$(LIBPATH) for the linker to find the library files

Install Python Libraries

Navigate to the directory containing setup.py and run the following command:

1
pip install .

Now you should be able to import and use the Glafic library in Python:

1
import glafic

Notes:

  • This guide assumes the user is working on a Linux system, likely Ubuntu.
  • The Python bindings are created via setup.py, and users need to ensure their system is set up to compile C code and link libraries.
  • Ensure you replace the paths with the correct installation locations, especially for the libraries, if they are in a custom directory.

Welcome to my other publishing channels