News for hackers. Stuff that matters.
Re:Python 2 Removed from Debian by leephillips on Tuesday January 03, 2023 @08:40AM (#34231145)
I agree completely, plus there are all the conflicting ways of installing and managing Python programs, dependencies, and environments, and the poor quality of so much Python code, some of it widely used. I find myself having to switch the `python` symlink in my path between python2 and python3 regularly, I look forward to the day when I can purge my systems of all traces of Python.
Re:Python 2 Removed from Debian by wildrhythms on Tuesday January 03, 2023 @10:04AM (#34232238)
The number of times I find a script that blindly assumes 'python' points to its required version is too damn high. It makes me question the general competency of the people shipping Python code.
Re:Python 2 Removed from Debian by leephillips on Tuesday January 03, 2023 @10:17AM (#34232394)
It’s inexcusable in recent scripts, but some of these date from the time when there was only python2. No, the root of the problem, as pointed out by many others here, is the policy decision to create two incompatible interpreters both called “python”.
Re:Python 2 Removed from Debian by jeroenhd on Tuesday January 03, 2023 @11:30AM (#34233608)
I think it's actually more excusable in recent scripts as Python 2.7 has been deprecated and unsupported for ages now.

You won't know what version of Python 3 you're getting, but at this point it's safe to assume you're getting a version of Python 3 when you call python.

Only old scripts written when Python 2 and 3 were maintained separately should've ever had this problem, but we're past that point now.

Re:Python 2 Removed from Debian by bloblaw on Tuesday January 03, 2023 @12:14PM (#34234343)
Yes, but *which* Python3? Are you getting one with f-strings support? Because if you aren't, now you've got to install that.

How about one with dataclasses support? Again, you get to install a new interpreter everywhere.

Python packaging continues to be a sore spot for the language.

Re:Python 2 Removed from Debian by jeroenhd on Thursday January 05, 2023 @08:40PM (#34269835)
You're getting the Python version you've specified as a requirement in your requirements.txt, unless your users ignore or bypass that. What language features you support depend on the minimum version you pick, and if you choose to go bleeding edge/not pick a version/pick a version and use newer features anyway, you're responsible for getting support to work.
Re:Python 2 Removed from Debian by bloblaw on Friday January 06, 2023 @02:07AM (#34271825)
But what if you just write a Python3 script and want to run it? Not a full blown application, but just a script.

I mean the Python ecosystem is such that now I have to "package" up this script to potentially tell the user with Python 3.6 that they need to download a new interpreter version (eg 3.9) to run my application (and any dependencies). This puts all the pain of running a script on every user that wants to run it.

I've said it before, but Python requires users to replicate the developers environment...and somehow this is fine?!? Statically compiled languages (eg Go, Nim, Rust, C/C++, Obj-Pascal, D, etc) ship binaries...that just run.

Obligatory xkcd: https://xkcd.com/1987/

Re:Python 2 Removed from Debian by jeroenhd on Friday January 06, 2023 @02:12PM (#34279378)
If you just want to write a script, you likely know the version available on your system.

When in doubt, add the #!/bin/env python3.10 shebang to the top of your script to ensure the version it's running on is the same as the version you're writing the script for.

If I build an application on Linux I need to specify a glibc version or a PHP version or a Java version in some way as well. I don't see what this has to do with Python. Good luck running a jar built with JDK19 on JRE8, or an executable linked against glibc2.36 on Ubuntu 18, or a Python file written for Python 3.10 on a system that comes with Python 3.6.

Statically compiled languages come with their own problems (note that C++, Go and Rust also have system requirements, I've had to deal with a Go executable that would not work in a musl environment and a Rust executable that I needed to build on Ubuntu because the compiled version from my Manjaro laptop linked a against a libc version that was too recent).

If you need dependencies, specify and install them. If your only dependency is the interpreter, document it, specify it in the shebang, or deal with it. Python 3 is completely backwards compatible in my experience, it's only the programs that stuck with Python 2 for a decade that have trouble running on modern machines in my experience.

Re:Python 2 Removed from Debian by bloblaw on Saturday January 07, 2023 @01:32AM (#34285766)
> Good luck running a jar built with JDK19 on JRE8, or an executable linked against glibc2.36 on Ubuntu 18, or a Python file written for Python 3.10 on a system that comes with Python 3.6.

Yes, you are starting to see the problem. This is why I recommend statically compiled binaries as a solution to this scenario, and do not recommend any of the above.

Here's a real scenario I've had in my career, when deploying a script to 350k systems. I know I have Python 3.x, but I cannot count on the fact that every (or most) clients will have even a functioning Python interpreter. So what's the solution? Ship a docker container to everyone? There are multiple ways to solve it, but I complied a statically linked binary instead of writing a Python script...and had no issues.

> If you need dependencies, specify and install them.

Here be dragons, and this is the entire reason I avoid Python when I need my code to 100% work on another machine I can't fully control. I choose statically compiled languages in these instances. In a server deployment...sure it's fine because I can control that.

> Python 3 is completely backwards compatible in my experience

I do not agree. F-strings were introduced in 3.6, so if you write a script that uses them and run across a system that doesn't meet 3.6 or better, your script will fail. Again, if you can ensure the system will have it (or you can donwload 30 mb and are able to install Dataclasses and 3.7 are the same problem. TypeDict in 3.8. All use of these will fail to function in a previous release.

Maybe you'll say that 3.6, 3.7, 3.8, etc are too old and so it's not a fair comparison. Or you'll say to just install a new version of Python. All that is overhead and requires more management. And what if you want to run that script on a bastion host, or a prod server, or a server you don't have ability to download and install external binaries? (all of these are real scenario's I've experienced).

My experience has taught me that if I can't control the machine the script runs on, I save headaches by using statically compiled languages. As always, YMMV.

Re:Python 2 Removed from Debian by wheelerof4te on Saturday January 14, 2023 @06:44AM (#34379501)
The only useful feature from that list are F-strings, which goes to show what joke of a language Python has become.
Re:Python 2 Removed from Debian by tusharsadhwani on Tuesday January 10, 2023 @08:51PM (#34334087)
requirements.txt doesn't support putting your python version in it
Re:Python 2 Removed from Debian by jeroenhd on Tuesday January 10, 2023 @10:01PM (#34334538)
You're right, I misunderstood environment markers.

However, you can ensure compatibility around this by specifying the required version in the top of your script:

    import sys
    minimum_version = (3,6,1)
    if sys.version_info < minimum_version:
        sys.exit("You need Python 3.6.1")
This will work because of how Python's tuple comparison works.

As long as you put this above any code requiring any specific version (this will work with Pyton 2.7, I don't have anything older to test) this will halt execution on dependency failures.

You can include these checks in your setup.py if you want to rely on Pip so users are warned on install time. You could probably also add this to some wheel trigger if you add a local/public package as a dependency in your requirements.txt.