What’s the correct process to install and run a .py application and its dependencies? Where should I save the .py file, where should I run it from, and can it interfere with the rest of my system?

Often there is an application/script I’d like to use and it is provided as a .py file download, along with a list of other applications/scripts that need to be installed separately for it to work. Often not all of these dependencies are available in my distro’s repository. There seems to be an assumption of prior knowledge as to how to get set up to run .py files, and it is therefore not documented on developers pages. Can anyone fill me in?

I’d like to install this application. Perhaps it could be used as an example to help explain the process.

My distro is Debian 13, in case that’s relevant.

Thanks!

      • jokeyrhyme@lemmy.ml
        link
        fedilink
        English
        arrow-up
        4
        ·
        2 months ago

        I think it should be a punishable offence to share Python scripts that depend on third-party packages without any ready-to-go bundling/isolation :)

        goes for any interpretted language where dependencies inevitably creep into the global namespace via distribution packagers that should know better :P

  • fizzle@quokk.au
    link
    fedilink
    English
    arrow-up
    4
    ·
    2 months ago

    I dislike installing python dependencies globally.

    It’s like keeping your vacuum cleaner, lawnmower, and washing machine in your living room.

    Someone mentioned virtualenv which I expect is the best way to encapsulate a set of python dependencies.

    That said, nix package manager on debian (not nixos) will provide the same encapsulation in a language agnostic way. As in, you can use it for python or node or rust or binaries or cli tools or GUI apps or anything really.

    Learning about nix just to run this one script is an over engineered solution, but I feel like its worth a mention because its definitely the best way to run anything you want in a way that won’t clutter up your living room.

    The details for creating a shell with python dependencies are here:

    https://wiki.nixos.org/wiki/Python

  • Jerkface (any/all)@lemmy.ca
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    2 months ago

    This is probably a problem with how the question is being asked, but…

    A .py file is not an application. It might be a component of an application but there is no general way to “install” a .py file. If you are coming from microsoft, you can think of a .py file as similar to a .bat file, but it might also be more like a .dll file.

    If the .py file contains a script meant to be run like a .bat file, you can to run it from wherever you saved it using the Python interpreter. That is what is occurring in this example from your page:

    python3 rectarg.py R230122W.cht R230122W.txt output.tif --target_dpi 300 --background GS10 --label_axis_visible X=B

    The user is using the python3 command to run the rectarg.py script from the current directory, and passing it arguments with the rest of the commandline. This doesn’t require installing rectarg.py, just knowing the path (or in this case, being in that path).

  • doodoo_wizard@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    2 months ago

    Hey when pip doesn’t work:

    You’re using Debian, so if you don’t want to set up virtual environments the best bet is to install your dependencies using apt like a normal person. All the python stuff in apt will show up under the prefix python3-. So you’ll need python3-numpy, python3-tiffile etc.

    Apt supports tab completion so something like “apt install python3-num” then the tab key would show a list of possible completions (and jump forward any letters that are common between completions).

    If you want to use venvs there’s a bunch of posts explaining how to do that.

    When you want to “install” the .py doohicky you just downloaded, put it in your path! $PATH will tell you what locations get scanned for executable files when you type something and you can add a local directory like ~/.bin to it, then put your .py file in there. If you go with venvs, put the .py file in the right place to run inside the venv, then make a one liner script that runs it from the venv with the file name set to what you wanna type to run the .py, put it in your local path directory and you’re off to the races!

    I also use Debian and am coerced into using python software so reply with any questions and I’ll set you straight.

    • Da Oeuf@slrpnk.netOP
      link
      fedilink
      arrow-up
      1
      ·
      2 months ago

      Thanks for the help! For some reason tab autocompletion doesn’t work for me but that’s an issue for another day…

      put the .py file in the right place to run inside the venv

      This could be where I’ve been getting lost. How do I figure out what the right place is?

      • doodoo_wizard@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        2 months ago

        One man’s right place is another man’s evidence of clinical insanity. You could just leave them on your desktop and invoke them through the venv. You could make a folder called Folder For Python Scripts That Don’t Run Good and put all your different python things there.

        You can also put the target python script inside the folder its respective venv lives in.

        Really the world is your oyster because ultimately you’re gonna make another script that does something like “read $a; ~./<venv_location>/python3 <target_.py_file> $a;” and naming it what you wanna type to run your .py and put it in your local $PATH directory.

        Don’t trust that one liner btw it’s definitley wrong.

        • Da Oeuf@slrpnk.netOP
          link
          fedilink
          arrow-up
          0
          ·
          2 months ago

          Ok, so am I understanding correctly that for example the .py can be anywhere, as long as it is run from a suitable venv folder and the path to it is defined in the command?

  • residentoflaniakea@discuss.tchncs.de
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    2 months ago

    You can run it in an virtual environment:

    python -m venv someproject

    source someproject/bin/activate

    Then you can run the commands in the git README you posted.

    pip …

    Will will install the include files needed within this virtual environment. Alternatively you can do

    apt install …

    Instead of using pip. Your python script should run within the virtual environment.

      • residentoflaniakea@discuss.tchncs.de
        link
        fedilink
        English
        arrow-up
        0
        ·
        2 months ago

        That might work but it is recommended to not install packages outside of virtual environments as it might lead to conflicts between versions across different projects.

      • corsicanguppy@lemmy.ca
        link
        fedilink
        English
        arrow-up
        0
        arrow-down
        1
        ·
        2 months ago

        Apt: safest for Debian

        Pip/pipx: kids dig it. See “supply chain attack”

        You do what you want to support and maintain.