Skip to content

Setting up the environment, building and running

DevilXD edited this page Dec 30, 2024 · 5 revisions

Preliminary note - Windows vs Linux

This guide's main purpose is to explain - in simple terms - how to setup the development environment on a Windows machine.

While there are some instructions included for Linux users as well, their scope has been limited to semi-advanced users only. If you'd like to contribute a more comprehensive instruction and/or description, please open a new issue for this repository.

Prerequisites

Windows

In order to setup the development environment for the application, you'll need to install both Python and Git. Here are two guides which will help you through the process:

Continuing past this point, you should have both of them installed with the configuration and steps explained in each guide, and your computer should be restarted (see the "Final note" section in either of the two guides above for details).

Linux

This guide assumes you're on a modern version of a Ubuntu-based Linux distribution. If you're on a different distro, the name of packages used below will likely be different, and you will need to adapt them yourself.

You'll need to install Git (git), Python 3 with Tkinter support (python3-tk), Python's package installer (python3-pip) and Python's virtual environment module (python3-venv).

For system tray support, you'll also need Ayatana's AppIndicator (libayatana-appindicator3-1), GObject introspection files for Ayatana's AppIndicator (gir1.2-ayatanaappindicator3-0.1), Python 3 development headers (python3-dev), Cairo 2D development headers (libcairo2-dev), Pycairo development headers (python3-cairo-dev), GObject introspection data development headers (libgirepository1.0-dev), pkgconf (pkg-config) and a C compiler (gcc).

In one apt install command:

sudo apt install git python3-tk python3-pip python3-venv libayatana-appindicator3-1 gir1.2-ayatanaappindicator3-0.1 python3-dev libcairo2-dev python3-cairo-dev libgirepository1.0-dev pkg-config gcc

Setup the environment

Windows

To setup the runtime environment for the application, first, download the source code. If you're using git, you can git clone https://github.com/DevilXD/TwitchDropsMiner the project into a folder of choice. Otherwise, you can download the source code from the main project's page by using the button shown below, and then unzip it into a folder of choice.

code-download

Once you have the source code, run setup_env.bat. This will create an env folder next to the source code files, and install all required Python packages inside it. Watch out for permission errors, you may need to run it as Administrator.

Linux

Once you have the source code, open a terminal window and use the cd command to navigate to the location of the source code. After that, run ./setup_env.sh. This will create an env folder next to the source code files, and install all required Python packages inside it.


Running from source

Windows

Run run_dev.bat to start the development build from source code. Starting without a console is perfectly fine, but you may want to start with a console if you'd expect errors to be printed out.

Linux

First, run source ./env/bin/activate to activate the Python virtual environment. Then, run python3 main.py to start the application with a console. Alternatively, you can run ./env/bin/python3 main.py to start the application directly inside the virtual environment, but without prior activation.


Building an executable

Windows

If you'd want to build an executable, run build.bat - this will create a dist folder with the resulting executable inside. PyInstaller will be automatically installed into the environment (env folder) on the first build attempt, and thus might require running it as Administrator. Subsequent builds should complete just fine with normal permissions.

Linux

If you'd want to build an executable, run ./build.sh - this will create a dist folder with the resulting executable inside. PyInstaller will be automatically installed into the environment (env folder) on the first build attempt.


Manual instructions

If you're one of those people who doesn't trust pre-made scripts, or you're interested in doing something those scripts haven't foreseen, here's some quick instructions which can get you up and running. Note that all commands assume you have Python and Git installed - if not, check out the prerequisites section at the top. Also, it's assumed you'll start your command prompt in the source code's directory, setting it as the current working directory.

  • You can use python -m venv env to create a virtual environment folder named env, inside the source code folder. Virtual environments are necessary to use here, because PyInstaller can be overly eager in terms of which libraries it tries to package, which would otherwise result in excessive build sizes and prolonged startup times, even 5x bigger/longer ones.
  • Once the virtual environment (venv for short) is created, you have to activate it. You can do so by running call ./env/Scripts/activate on Windows or source ./env/bin/activate on Linux. This should prepend an (env) ... prefix to your command prompt, indicating you've successfully activated the venv.
  • With the venv activated, running pip install -r requirements.txt should install all required packages into the virtual environment. Please ensure it's activated properly before doing so, otherwise the packages will be installed in your system-global Python installation instead, where you won't be able to use them. A warning stating a pip update can be performed is normal and a non-mandatory thing for you to take care of.
  • With the packages installed and still in the activated venv, you can run the application with python main.py. This will start it with an extra console window, to which any eventual Python error might be printed into. Because during normal operation it's entirely not needed, you can hide it by starting the application with pythonw main.py instead.
  • If you'd wish not to have to activate the venv every time you run the application, it's also possible to use the venv's executables directly. ./env/Scripts/python main.py (bin replaces Scripts on Linux) will start the application from the venv, without having to activate it first. Feel free to create yourself a shortcut that'll do that for you, or consider building the application into an executable form.
  • In order to build an executable, you'll need an extra package called PyInstaller. Install it into an activated venv via pip install pyinstaller, then with the venv still activated, run pyinstaller build.spec. All information related to building the application are already defined in the build.spec file for your convenience. Both Windows and Linux executables are supported.
Clone this wiki locally