Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

458
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda