MyRadio German (InternetradioDeutsch) Python3 - some modules missing

Hello to everyone!
I’ve tried to load the program InternetradioDeutsch via terminal as a python3 program without installing. Instructions via ubuntuusers.de (source: myRadio › Howto › Wiki › ubuntuusers.de).

wget ‘https://raw.githubusercontent.com/Axel-Erfurt/InternetRadioDeutsch/master/InternetRadioDeutschInstallation.sh’ -O ~/Downloads/InternetRadioDeutschInstallation.sh && chmod +x ~/Downloads/InternetRadioDeutschInstallation.sh && ~/Downloads/InternetRadioDeutschInstallation.sh

I’ve tried to install all dependencies. But the installation doesn’t work because some packages are missing like “requests” and some. But I’ve installed “requests” from python3.11 and python3.10 in the nix-store.

Where is my mistake? Can somebody help me? Thank you so much.

NixOS 23.11 KDE
Beginner in NixOS but experienced in other distributions like Debian, Arch, Mint and Garuda.

I don’t have much time to do it right now, but I would not bother trying to run this script (to be honest I see no fundamental reason why it would not work but it anyway does quite dirty modifications in your home folder). Instead, you might want to try to package it properly by creating a setup.py like:

#!/usr/bin/env python

from setuptools import setup, find_packages

setup(name='InternetRadioDeutsch',
      version='0.0',
      # Modules to import from other scripts:
      packages=find_packages(),
      # Executables
      scripts=[
          "myRadioD.py",
          "myRadioEditorDE.py"
      ],
      )

and a derivation.nix like

{ lib
, stdenv
, fetchFromGitHub
, python3Packages
}:

python3Packages.buildPythonApplication rec {
  pname = "InternetRadioDeutsch";
  version = "0.0";

  postPatch = ''
    cp ${./setup.py} setup.py
  '';
  
  src = fetchFromGitHub {
    owner = "Axel-Erfurt";
    repo = pname;
    rev = "584d52faabe0f66092644fd0ace2ab974b4f3779";
    sha256 = "sha256-Ip85no/z9KC+RxZg2xT0lPgCh/IGd8+xQr2rnICWqfI=";
  };

  build-system = with python3Packages; [
    setuptools
    wheel
  ];

  dependencies = with python3Packages; [
    requests
  ];

}

and a default.nix like

{ pkgs ? import <nixpkgs> {} }:
pkgs.callPackage ./derivation.nix {}

and build with nix-build, the result are in the ./result folder. I need to go right now, but you now need to find the good commands to add in the setup.py folder to specify that editor_intern.py must be used as a library, and to move the .txt files and images/.desktop in the share folder.

1 Like

I got to

{ lib
, stdenv
, fetchFromGitHub
, python3Packages
}:

python3Packages.buildPythonApplication rec {
  pname = "InternetRadioDeutsch";
  version = "0.0";

  # The code of this program is really dirty... You also need to create this folder yourself with
  # mkdir -p ~/.local/share/InternetRadioDeutsch/
  # as it will try to copy a backup of this file.
  postPatch = ''
    cp ${./setup.py} setup.py
    substituteInPlace myRadioEditorDE.py --replace-fail "mychannels_file = f'{QDir.homePath()}/.local/share/InternetRadioDeutsch/myradio.txt'" "mychannels_file = f'$out/bin/myradio.txt'"
    
  '';
  
  src = fetchFromGitHub {
    owner = "Axel-Erfurt";
    repo = pname;
    rev = "584d52faabe0f66092644fd0ace2ab974b4f3779";
    sha256 = "sha256-Ip85no/z9KC+RxZg2xT0lPgCh/IGd8+xQr2rnICWqfI=";
  };

  build-system = with python3Packages; [
    setuptools
    wheel
  ];

  dependencies = with python3Packages; [
    requests
    pyqt5_with_qtmultimedia
    pandas
  ];

  # Quite dirty, but they search for the .txt files where the python script is located
  postInstall = ''
    cp myradio.txt $out/bin
    cp exclradio.txt $out/bin
    cp *.png $out/bin
  '';
  
}

and

#!/usr/bin/env python

from setuptools import setup, find_packages

setup(name='InternetRadioDeutsch',
      version='0.0',
      # Modules to import from other scripts:
      packages=find_packages(),
      py_modules=["editor_intern"],
      # Executables
      scripts=[
          "myRadioD.py",
          "myRadioEditorDE.py",
          "RadioFinderD.py"
      ],
      )

image

Still need to do the desktop item, not so much time now.

EDIT
I got the time to work on it a few more mn, see my edit… but this program is really poorly made as every path is hardcoded, and rarerly in the good folder without following the XDG specification. For this reason, you need to create yourself

$ mkdir -p ~/.local/share/InternetRadioDeutsch/

as it will try to copy some backup there

1 Like

Thanks for the instructions. It doesn’t work. “Requests” is still missing. I uninstalled the 3.10 packages so I only kept the 3.11 versions. I previously had both versions installed because they were in the sources and I wanted to be sure.

I try it tomorrow but in case anyone have a tip for me I’m thankful. I wish you a good weekend.

The above instructions should be independent of what is installed on your system. Can you run them and take a screenshot oh the error?

Also, it’s unrelated to my above solution, but how do you install requests? Do you use python3.withPackages? If not it is expected to fail. Notably, can you import request when you start python?

Thanks for the answer. I installed the single packages, not the meta package you called. I try it with your named package in the afternoon or evening and give you an answer. :blush:

I’ve installed new the program with your instructions (I’ve installed now python3Full). And now comes this error (I’ve this command copied from the terminal):

[nurzumspassda@nixos:~/.local/share/InternetRadioDeutsch]$ python3 myRadioD.py
File “/home/nurzumspassda/.local/share/InternetRadioDeutsch/myRadioD.py”, line 2
PATH=${PATH:+‘:’$PATH’:'}
^
SyntaxError: invalid syntax

In the myRadioD.py stand this information:

This were in home/.local/share/InternetradioDeusch as in the install folder with the nix-build-file (bin). In both folders the program doesn’t work.

I believe this program is too specialized for NixOS. I think about alternatives.

So I tried simply to type:

$ nix-shell -p "(python3.withPackages (ps: with ps; [ pyqt5_with_qtmultimedia requests pandas ]))"

and to follow there instructions by doing:

$ bash InternetRadioDeutschInstallation.sh

and it runs the program on my side (though, is it supposed to play any sound?)

I believe this program is too specialized for NixOS. I think about alternatives.

Well, it is not really well coded it seems, at least it is more thought as a quick script than as a program to actually install (nothing impossible to fix, just that they assume for instance that the .txt radio file is installed in the user folder, but if you install a program system-wide it has no chance to be)

??? What have you done here? This file is the wrapper created by nix, have you copied somehow? You should run binaries wih ./myRadioD.py, do not add python in front… but I don’t understand why it is not in a ./result file if you followed my instructions above.

I’ve written the nix-build command in the terminal so you say in post #3. Then there come some files in the result folder but no bin. That’s okay, the program is, you say it right, more a script than a program. But the script is written in Python3 so the author Axel Erfurt says. So I started the myRadio.py-file with Python3. But then comes the error.

The file should be in ./result/bin/myRadioD.py otherwise you did something wrong. If it is present, just run it with

./result/bin/myRadioD.py

and python will automatically be called with the right version and packages.

You have to understand that if you write a derivation as we did, nix will try to maintain purity : so it will wrap automatically the python file in order to provide the good version of python with all packages. So if you use python3 yourscript, you are trying to use a different version of python, maybe not even with the right packages. So just run the script with ./result/bin/myRadioD.py and let nix do the magic of using the good version of python with all packages for you :wink: And if you need more packages, change the derivation.nix.

Or the other (maybe simpler if you are not used to nix) is to use the above commands with python3.withPackages and then you can just run the instructions for ubuntu.

Thanks. It works. :slight_smile:

Happy Easter!