IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Install Pyhton module Fifi, a library for finite field arithmetics

    SparkandShine发表于 2017-03-20 12:43:48
    love 0

    In this post, I’d like to introduce how to intall Python module fifi-python, a library for finite field arithmetics, provided by Steinwurf.

    1. Fifi

    Fifi is a library for finite field arithmetics, developed by Steinwurf company. It provides Python wrappers for fifi (written in C++), which is so-called fifi-python.

    2. Authenticate to GitHub

    Following the installation guide of README.rst in fifi-python, I encountered the issue of “Permission denied (publickey)”.

    $ git clone git@github.com:steinwurf/fifi-python.git
    Cloning into 'fifi-python'...
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    

    A “Permission denied” error means that the server rejected my connection. To connect to GitHub with SSH, I need to configure SSH authentication first.

    Step 1: Generate a new SSH key

    $ cd ~/.ssh && ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/sparkandshine/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /Users/sparkandshine/.ssh/id_rsa.
    Your public key has been saved in /Users/sparkandshine/.ssh/id_rsa.pub.
    The key fingerprint is:
    ...
    The key's randomart image is:
    ...
    

    Step 2: Add the new SSH key to the GitHub account

    Copy the contents of the id_rsa.pub file to your clipboard,

    # macOS
    $ cat id_rsa.pub | pbcopy
    
    # Linux
    $ cat id_rsa.pub | xclip
    
    # Windows (via Cygwin/Git Bash)
    $ cat id_rsa.pub | clip
    

    Then, follow the instruction of Authenticating to GitHub / Adding a new SSH key to your GitHub account and add the new SSH key (in the clipboard) to my GitHub account.

    Step 3: Test the SSH connection

    $ ssh -T git@github.com
    Hi sparkandshine! You've successfully authenticated, but GitHub does not provide shell access.
    

    3. Install fifi-python

    Request a license

    A valid license is required to use this library. Obtain a license by filling out a license request form (here). It is free for non-commercial research and teaching.

    Download the repository

    $ git clone git@github.com:steinwurf/fifi-python.git
    Cloning into 'fifi-python'...
    remote: Counting objects: 292, done.
    remote: Total 292 (delta 0), reused 0 (delta 0), pack-reused 292
    Receiving objects: 100% (292/292), 355.21 KiB | 286.00 KiB/s, done.
    Resolving deltas: 100% (158/158), done.
    Checking connectivity... done.
    

    Build from source

    $ cd fifi-python/
    $ python waf configure
    ...
    'configure' finished successfully (3.588s)
    
    $ python waf build
    ...
    [108/108] Linking build/darwin/src/fifi_python/fifi.so
    Waf: Leaving directory `/Users/sparkandshine/git/fifi-python/build/darwin'
    'build' finished successfully (1m40.314s)
    

    Execute the test case

    su-macbook:fifi-python sparkandshine$ cd examples/                  
    su-macbook:examples sparkandshine$ python hello_fifi.py 
    13 + 7 = 10
    13 - 7 = 10
    13 * 7 = 5
    13 / 7 = 8
    ~13 = 4
    

    Using PYTHONPATH

    Add fifi.so (under build/platform/src/fifi_python/) to PYTHONPATH,

    # Add the following line to `~/.profile`
    export PYTHONPATH='/Users/sparkandshine/git/fifi-python/build/darwin/src/fifi_python/'
    
    # Make it effect
    $ source ~/.bash_profile 
    

    This doen’t work for me. Instead, to make fifi work outsider the folder of fifi-python/, I copy fifi.so (which is located in fifi-python/build/darwin/src/fifi_python/) next to my python file. It works for me.

    cp /Users/sparkandshine/git/fifi-python/build/darwin/src/fifi_python/fifi.so git/mathematics/abstract_algebra/finite_field/
    

    References:
    [1] StackOverflow: Git – Permission denied (publickey)
    [2] Authenticating to GitHub / Connecting to GitHub with SSH
    [3] Authenticating to GitHub / Error: Permission denied (publickey)



沪ICP备19023445号-2号
友情链接