Skip to content

Setting up the environment, building and running

DevilXD edited this page Oct 29, 2023 · 4 revisions

Prerequisites

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).

Setup the environment

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.

Running from source

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.

Building an executable

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.

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.