this post was submitted on 25 Feb 2026
40 points (93.5% liked)

Linux

63238 readers
835 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS
 

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!

top 25 comments
sorted by: hot top controversial new old
[–] jokeyrhyme@lemmy.ml 19 points 16 hours ago (1 children)
[–] Liketearsinrain@lemmy.ml 4 points 15 hours ago (1 children)

Insert "xkcd" for everything. I am happy with the move to disallowing system pip install at least.

[–] jokeyrhyme@lemmy.ml 1 points 8 hours 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

[–] jerkface@lemmy.ca 26 points 1 day ago* (last edited 1 day ago) (1 children)

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

You also need to make sure all the dependencies are installed. Those are usually listed in a requirements.txt file and can be installed with pip.

[–] doodoo_wizard@lemmy.ml 9 points 21 hours ago (1 children)

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.

[–] oeuf@slrpnk.net 3 points 16 hours ago (1 children)

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 4 points 16 hours ago (1 children)

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.

[–] oeuf@slrpnk.net 3 points 14 hours ago (1 children)

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?

[–] doodoo_wizard@lemmy.ml 4 points 13 hours ago

Yeah, a python venv has two parts, one part is just a bunch of copies of some basic python shit that you know you’re gonna need, that’s honestly 99% of what you want when you do a venv and need to install a million stupid piles of crap by copy pasting a pip one liner into your shell.

You use this part by just invoking your python3 or pip command inside the venv folder. So ~./<venv_location>/pip install <joes_dumb_crap> or something.

The other one percent is actually invoking the venv which is a really important one percent in terms of not being a guy who plays fast and loose with his systems security and privacy when messing around with totally trustworthy python stuff. It’s only one percent because tbh no one is that guy they’re all the “do whatever just make it run” guy.

So you could have a script file called rectarg in your local path folder that invokes rectarg.py using the python3 executable inside your venv folder and passes whatever you type after “rectarg” straight to rectarg.py.

[–] residentoflaniakea@discuss.tchncs.de 14 points 1 day ago* (last edited 1 day ago) (1 children)

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.

[–] florge@feddit.uk 6 points 1 day ago (2 children)

What's the difference between doing this and just using pipx?

[–] residentoflaniakea@discuss.tchncs.de 4 points 23 hours ago (1 children)

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.

[–] IrritableOcelot@beehaw.org 3 points 20 hours ago (1 children)

Just FYI, pipx does use a virtual environment behind the scenes. The idea with pipx or uvx is to install a python script as a standalone script.

I did not know that, I assumed they wrote pipx to mean pip/pip3. Thanks for pointing that out.

[–] corsicanguppy@lemmy.ca 0 points 16 hours ago

Apt: safest for Debian

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

You do what you want to support and maintain.

[–] fizzle@quokk.au 11 points 1 day 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

[–] emb@lemmy.world 4 points 1 day ago* (last edited 1 day ago) (1 children)

If you actually just download a .py file, you need to run it with python. Like in the example you linked, something like

python3 _filename_

(and if that's the case, you might need to add a line at the top of the file, telling it where the interpreter is. But probably you actually want the following)

To install, you use the python installer program, pip. Something like

pip _package-name_

Before you do either, you need to install python and pip. I don't know exactly (look for correct package names), but you need to run something like

sudo apt install python3 pip
[–] infeeeee@lemmy.zip 7 points 1 day ago

No, pip is for libraries, and for running scripts in virtual environments (venv). Recent versions of pip don't work outside venvs. For installing packages systemwide use something like pipx, which creates venvs automagically and runs the script there.

[–] ejs@piefed.social 1 points 20 hours ago (1 children)

I’d recommend installing those python dependencies using apt, so that when you update your system packages, the python libraries get updated, too. Pip, on the other hand, is useful for development but is detatched from apt and you will definitely forget to pip update unlike apt update which you hopefully do frequently. Use the names of the packages the readme provides in the pip install … instruction. For example, for numpy, you can install this.

Then, since that python script has a shebang at the top, you can add it to a directory in your $PATH and mark it executable with chmod, and you can invoke the script in your shell from any directory with just the file name.

[–] lazynooblet@lazysoci.al 1 points 17 hours ago (1 children)

The pip library of modules is many times larger than those available in the distro repo.

[–] corsicanguppy@lemmy.ca 1 points 16 hours ago

As popularity doesn't equal validity, repo size isn't a measure of safety.

Ask a system person about the massive validation hole in pips (and dockers and CPAN and composer bits and venvs and crates and gems) and why enterprise people and the safety-aware avoid this like it's toxic.

[–] tourist@lemmy.world 3 points 1 day ago (1 children)

Other comments did a good job

Just making sure, how familiar are you with using the terminal?

The GitHub repository you linked is terminal-only

[–] oeuf@slrpnk.net 2 points 16 hours ago

Good question. I'm quite familiar with the terminal, but I still get confused by things in it that I'm not familiar with, if that makes sense!

[–] just_another_person@lemmy.world 2 points 1 day ago* (last edited 1 day ago)

You don't need to "Install" them like in Windows. Everything in Linux is just a call to launch something, and for Python is just python someprogram.py.

If you're regularly going to be calling this program, you can put it anywhere makes sense for you, but generally somewhere in your PATH, and then you can make an alias for your preferred terminal to launch it easily.

If that's super confusing, give this a try (cross platform): https://github.com/InkAurora/PythonAliasManager