ninia / jep

Embed Python in Java
Other
1.28k stars 145 forks source link

pip install . fails #462

Open patenaud opened 1 year ago

patenaud commented 1 year ago

I get this error when trying to install via pip (pip install jep) or local source install (pip install .). Java and numpy requirements are installed. Runnin a python 3.11 virtual env.

/usr/bin/ld: /usr/local/lib/libpython3.11.a(ast_opt.o): warning: relocation against PyExc_RecursionError' in read-only section.text.unlikely' /usr/bin/ld: /usr/local/lib/libpython3.11.a(abstract.o): relocation R_X86_64_PC32 against symbol `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: bad value collect2: error: ld returned 1 exit status error: command '/usr/bin/gcc' failed with exit code 1

java --version openjdk 17.0.6 2023-01-17 LTS OpenJDK Runtime Environment Corretto-17.0.6.10.1 (build 17.0.6+10-LTS) OpenJDK 64-Bit Server VM Corretto-17.0.6.10.1 (build 17.0.6+10-LTS, mixed mode, sharing)

numpy==1.24.2

$PATH /home/devop/py311_venv/bin:/usr/lib/jvm/java-17-amazon-corretto/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/opt/gradle/gradle-8.0.2/bin

bsteffensmeier commented 1 year ago

We do not support building with a python installation with a statically linked libpython(libpython3.11.a). I recommend installing a version of python that provides a dynamically linked libpython(libpython3.11.so).

patenaud commented 1 year ago

Thank you. I was able to install jep outside of my 3.11.2 python virtual env. I'm not sure why. I've got "googling" to do to better understand virtual environments.

svensk-pojke commented 1 year ago

Hi Nate and Ben,

I experienced this problem when trying to pip install jep in a venv. It turns out the linker looks in ~/.local/lib for the libpython3XX.so library, but it is not there, it is in the site installation area, in /usr/lib/x86_64-linux-gnu (for Mint/Ubuntu). There is a static library in the local lib dir, which causes the error. I carefully searched through the wiki and tried setting LD_LIBRARY_PATH, LD_PRELOAD, LIBDIR and LDLIBRARY, but nothing worked. I finally got it to work by putting a link in ~/.local/lib to the site installation library:

libpython3.10.so -> /usr/lib/x86_64-linux-gnu/libpython3.10.so

Is there a better way to do this when working with a venv?

Thanks! Erik

bsteffensmeier commented 1 year ago

I don't know much about venv but I do have a variety of Dockerfiles that I use to test jep in various environments. Here is a Dockerfile that I use to test venv and it works without any extra linking. I recommend you compare that env to what you are using.

FROM python:3.10
RUN apt-get update && apt-get install --no-install-recommends -y openjdk-17-jdk-headless && apt-get clean
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
WORKDIR /jep
RUN python3.10 -m venv venv-dir
RUN . venv-dir/bin/activate && pip install numpy
RUN . venv-dir/bin/activate && pip install jep

CMD /jep/venv-dir/bin/jep
svensk-pojke commented 1 year ago

Thanks for the response, Ben. I think this must be some kind of configuration issue on my end. I just tried pip installing jep on a laptop running Mint 21.1 (Ubuntu 22.04) and everything works fine. It still fails on my other machine, which is Mint 20.3 (Ubuntu 20.04). I used essentially the same steps that you outline above. I plan to upgrade my other machine anyway, so this is not an issue. Thanks again for the response.

enricostara commented 2 months ago

I having exactly the same issue! I just tried to run the same commands you have in dockerfile.. no way, I got the following error:

      /usr/bin/ld: /usr/local/lib/libpython3.10.a(myreadline.o): relocation R_X86_64_PC32 against symbol `_PyOS_ReadlineTState' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/libpython3.10.a(mystrtoul.o): relocation R_X86_64_PC32 against symbol `_Py_ctype_table' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: final link failed: nonrepresentable section on output
      collect2: error: ld returned 1 exit status

Do you have any other tips?

ndjensen commented 2 months ago

If you compiled your own python, you need to recompile it with the --enable-shared flag passed to configure.