Skip to content

Instantly share code, notes, and snippets.

@CodingCryptoTrading
Created April 28, 2022 20:39
Show Gist options
  • Save CodingCryptoTrading/005fc6dc23e1d6012ac5ad74e2e55851 to your computer and use it in GitHub Desktop.
Save CodingCryptoTrading/005fc6dc23e1d6012ac5ad74e2e55851 to your computer and use it in GitHub Desktop.

Installing Python 3.8 and ccxt on Raspbian

The latest version of Raspbian (as of April 2022) includes python 3.9. However, if you are running an older Raspbian version, you probably cannot get anything better than python 3.5. This means you will have to build it yourself. You will also need to build every single python package. While many python packages (such as Numpy, Pandas and Matplotlib) are straightforward to build, Ccxt (CryptoCurrency eXchange Trading Library) requires some extra steps since it needs the rust compiler.

Installing Python

  1. Install the required build-tools (some might already be installed on your system).

     $ sudo apt-get update
     $ sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev
    

    If one of the packages cannot be found, try a newer version number (e.g. libdb5.4-dev instead of libdb5.3-dev).

  2. Download and install your preferred Python release. We opted for the release 3.8.10. Select the release link on the official site. Adjust the file names accordingly.

     $ wget https://www.python.org/ftp/python/3.8.10/Python-3.8.10.tar.xz
     $ tar xf Python-3.8.10.tar.xz
     $ cd Python-3.8.10
     $ ./configure
     $ make
     $ sudo make altinstall
    

    If you want to install python in a specific disk location replace the ./configure with:

     $ ./configure --enable-optimizations --prefix=/path/of/your/choice
    

Installing common scientific packages

We will now compile some common python packages. Each one of them needs to be compiled, and such operation, especially on an old Raspberry Pi, can take many hours.

  $ python3.8 pip3.8 install numpy
  $ python3.8 pip3.8 install matplotlib
  $ python3.8 pip3.8 install pandas

Since the process is long, you may consider running the above commands using nohup. In this way, even if the shell is closed, the process will still run. For example:

  $ nohup python3.8 pip3.8 install numpy > numpy.txt &

And at any time you can check the installation progress by running:

  $ tail -f numpy.txt

Installing ccxt

Before building ccxt we need to install the rust compiler. The installation command is the following:

  curl https://sh.rustup.rs -sSf | sh

The above command will install the compiler in the home directory (in .cargo and .rustup). If you want to change the default behaviour (for example, in case you don't have enough space on the sd card, you may install it on an external drive) you can specify the installation folders by adding the below lines to your .bashrc file:

  export CARGO_HOME=/path/of/your/choice/.cargo
  export RUSTUP_HOME=/path/of/your/choice/.rustup

Then, source the .bashrc file (or open another shell running bash) and run the above installation command.

To check that everything is fine, try to run:

  $ rustup toolchain list

you should get something like:

  $ stable-armv7-unknown-linux-gnueabihf (default)

Once the compiler is installed, you can compile ccxt by running (as above, you may want to use nohup to run it):

  $ python3.8 pip3.8 install ccxt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment