# Install G6K inside Sage on macOS

I want to install g6k on my computer, but I encountered some problems. Fortunately, I finally solved them one by one.

When I searched for a solution on the Internet, I did not find a tutorial for installing g6k on macOS, so I sorted out the problems and solutions I encountered, hoping to be helpful to you who need to install g6k.

## What is G6K

G6K is a C++ and Python library that implements several Sieve algorithms to be used in more advanced lattice reduction tasks. It follows the stateful machine framework from:

Martin R. Albrecht and Léo Ducas and Gottfried Herold and Elena Kirshanova and Eamonn W. Postlethwaite and Marc Stevens, The General Sieve Kernel and New Records in Lattice Reduction.

You can also see its introduction on GitHub.

## My environment information

This record may only be useful for my environment and the problems I encountered.

• System: macOS Catalina 10.15.7

• Sagemath version: 9.1

• Python version (inside Sage): 3.7.3

• pip source: https://pypi.tuna.tsinghua.edu.cn (you may need to set it if you’re in china)

• Git port：10800 (my v2ray port, to across the gfw)

### Check pip inside Sage

Since pip may not be used in sage -sh due to OpenSSL, you need to compile OpenSSL in sage -sh, which takes half an hour.

 1  sage -python3 -m pip install virtualenv 

If it can be installed, it means that your pip is ok : )

## Start installation

### Download and Edit source code

#### Download

 1  git clone https://github.com/fplll/g6k.git 

or

 1  curl https://github.com/fplll/g6k/archive/refs/heads/master.zip 

#### Edit source code

You can use vs code, vim or other editors you like.

1. g6k/kernel/fht_lsh.cpp:364:17: Change std::fabs to fabs;

2. g6k/kernel/bdgl_sieve.cpp:313:55: Change cdb[std::min(S-1, insert_after+params.threads*write_index)] to cdb[fmin(S-1, insert_after+params.threads*write_index)];

Or you can directly download the g6k I forked, I have completed these two changes in it

 1  git clone https://github.com/Am473ur/g6k.git 

### Installation

  1 2 3 4 5 6 7 8 9 10 11 12  cd g6k sage -python3 -m pip install virtualenv # my sage -python3 path is: /Applications/SageMath-9.1.app/Contents/Resources/sage/local/bin/python3 PYTHON=/Applications/SageMath-9.1.app/Contents/Resources/sage/local/bin/python3 ./bootstrap.sh # The path where my g6k is located is /Users/amateur/Documents/G6K/g6k # After installation, I can use g6k in anywhere like this: sage -python3 >>> import sys >>> sys.path.append('/Users/amateur/Documents/G6K/g6k') >>> import g6k 

But I want to use g6k more conveniently, like this:

 1 2  sage -python3 >>> import g6k 

I can view the path default included in python like this:

 1 2 3 4  sage -python3 >>> import sys >>> sys.path ['', '/Applications/SageMath-9.1.app/Contents/Resources/sage/local/lib/python37.zip', '/Applications/SageMath-9.1.app/Contents/Resources/sage/local/lib/python3.7', '/Applications/SageMath-9.1.app/Contents/Resources/sage/local/lib/python3.7/lib-dynload', '/Applications/SageMath-9.1.app/Contents/Resources/sage/local/lib/python3.7/site-packages'] 

Then let’s enter the site-packages path: /Applications/SageMath-9.1.app/Contents/Resources/sage/local/lib/python3.7/site-packages

 1 2 3 4 5 6 7  cd /Applications/SageMath-9.1.app/Contents/Resources/sage/local/lib/python3.7/site-packages # Create a new file with any name, but the extension must be .pth vim MyModules.pth # Then type i to insert the g6k path: /Users/amateur/Documents/G6K/g6k # Type esc to exit insert mode, type :wq to save and quit vim 

Now you can use g6k very conveniently.

 1 2  sage -python3 >>> import g6k