Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

460
Vistas
How can I install Python libraries using Jython Standalone in Java?

I am trying to install Python libraries using a Jython Standalone jar in Java.

The code I have seems to install PIP 7.1.2 in a folder next to the standalone jar, but once I try to use PIP to upgrade itself, it fails with a ZipImportError.

The error message seems to complain about not being able to open the PIP wheel file, but the log seems to show it being able to open it a few times already.

import org.python.util.PythonInterpreter;

public class PipInstaller{
    public void installPip(){
        PythonInterpreter python = new PythonInterpreter();
        runEnsurePip(python);
        upgradePip(python);
        python.close();
    }

    private void runEnsurePip(PythonInterpreter python){
        StringBuilder script = new StringBuilder();
        script.append("import ensurepip\n");
        script.append("ensurepip._main()");
        python.exec(script.toString());
    }

    private void upgradePip(PythonInterpreter python){
        StringBuilder script = new StringBuilder(); 
        script.append("import pip\n");
        script.append("pip.main(['install', '--upgrade', 'pip'])"); 
        python.exec(script.toString());
    }
}

These are the last couple lines of the stacktrace:

File "/tmp/tmpnmI49K/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/html5lib/html5parser.py", line 27, in parse
File "/tmp/tmpnmI49K/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/html5lib/treebuilders/__init__.py", line 69, in getTreeBuilder
zipimport.ZipImportError: zipimport: can not open file: /tmp/tmpnmI49K/pip-7.1.2-py2.py3-none-any.whl

These are the stackoverflow posts I used to get where I am now:

Installing python module within code

How can I install various Python libraries in Jython?

I am running Java 1.8, Gradle 2.14.1, Jython Standalone 2.7.1b3, and Ubuntu 16.04

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda