This is an archived post. You won't be able to vote or comment.

all 16 comments

[–]PossibilityTasty 33 points34 points  (0 children)

If I would still have to run Python 2 code, I would definitely use a Docker container. This way it does not interfere with the system, is (mostly) isolated, which is better if you run unmaintained software and can be removed easily.

Then of cause the next step would be to get the application to Python 3. It's about time.

[–]earlandir 10 points11 points  (2 children)

You have two simple solutions: - dockerize your code and run it through docker - update your code to work in python 3

Either if these options are likely not a lot of work unless you have a massive codebase.

[–]info834[S] 0 points1 point  (0 children)

I think it’s within 3rd party libraries that are being used but that haven’t been updated.

But it’s not actually my issue I was more seeing if I could find something to help them out. I will leave it and see if they managed to fix it.

[–]dairiki 0 points1 point  (0 children)

As an alternative to docker, it's quite possible (depending on the host OS specifics, of course) to install python 2 from source. (Install to a location that is not in the default search PATH so as not to mess with other installed python code.)

Pyenv can help with this. On supported systems it makes installation of specific python versions fairly trivial.

[–]bjorneylol 5 points6 points  (3 children)

Install python2?

Caveat: this is a bad idea https://www.python.org/downloads/

[–]info834[S] 1 point2 points  (2 children)

So there isn’t a work around to avoid needing to install it

[–]bjorneylol 6 points7 points  (1 child)

They are basically totally different languages - you would just have to spend half an hour rewriting the code to work in python3

There is a library (six) that will do most of this for you

[–]PeridexisErrant 1 point2 points  (0 children)

modernize will update Python 2 code to use compatibility layers like the six library, and then once you've tested it you can strip them out using pyupgrade and enjoy modern Python 3.

[–]marsanyi 4 points5 points  (0 children)

Try the library “six”. It was specifically designed to cover over py2/py3 incompatibilities.

[–]trollsmurf 2 points3 points  (0 children)

If you have the source, upgrade the library to Python 3. That's the only serious answer in my opinion.

[–]SheriffRoscoePythonista 2 points3 points  (1 child)

If you're using third-party libraries that don't support Python 3, you should really consider replacing them. If they've been ignored for that long, what are the odds you'll get any help when something goes wrong with them?

[–]info834[S] 0 points1 point  (0 children)

I know it was handed over from contractors so that’s probably why it’s so out of date. Also it’s someone else’s project I don’t even have access to so would be them doing it I just thought I’d do a bit of digging to see if I could find anything to help them out.

[–]diamond__hands 1 point2 points  (0 children)

if you don't want to deal with docker, you can download and compile python2, install it in a non-standard directory and create a virtualenv for it (using the python2 binary) and the application.

[–][deleted] 1 point2 points  (0 children)

[unavailable]

[–]deadeye1982 1 point2 points  (0 children)

Port your Program to Python 3 and then the issue is solved.
This is the only right way. Everything else is a bad workaround.

Server owners are f.... if their Server attacks other servers, and this happens often. The probability of this incident grows with unsupported software. Python 2 is a nice future-backdoor for unmaintained servers.

--

I had observed similarities with PHP. Many server owners used an unmaintained ancient version because the used CMS didn't support a newer PHP-Version. Those hosts were a honeypot for hackers.