简体   繁体   中英

Use an older python version in Ubuntu when executing a binary from Java using ProcessBuilder

I have a Java SpringBoot app that does audio processing and builds to a docker container based on Ubuntu. The app uses a third-party binary tool ( https://github.com/shaka-project/shaka-packager ) like

ProcessBuilder pb = new ProcessBuilder();
pb.command("shaka-packager", "-input foo", "-output bar");
pb.start().waitFor();

Problem: We started updating versions of Java, etc, and are using a newer version of Ubuntu 22.04, which comes with Python 3.10. This broke shaka-packager, because it has some python component that does from collections import Mapping , which has been deprecated and moved to collections.abc .

I'm trying to figure out if there is a way I can run the shaka packager in a virtual 3.9 python environment. I messed around with conda for a bit, but can't seem to get it to work with Java's ProcessBuilder calls. conda activate works in interactive shells, but ProcessBuilder creates a new shell for every invocation. I thought conda run would do it, but it seems to only work with python scripts and not compiled binaries.

Any suggestions on how to approach this? I could fork shaka packager and fix the python script that's failing (and submit a PR), but I would prefer not maintaining our own fork long-term if the owner doesn't merge it. I would also love to move away from a binary and use a Java library instead, but haven't found one that does everything shaka can do and I don't think I have the time to experiment with a mix of different libraries to get full feature parity.

I recommend you to install Python3.9 from PPA:

$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt install python3.9

Now you can use python3.9 :

$ python3.9 --version
$ python3.9 -m pip install -r requirements.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM