-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with dynamic linkage, how to find what env is in use? #2647
Comments
Venvs/Virtualenvs work by customizing the Python initialization step. For setting up embedded CPython, also take a look at the embedding API and specifically Python path configuration to let the embedded interpreter find stuff. When a version is compiled with
|
Compiling the LD library path into the exe will mean that if that app is later run outside the pyenv, and assuming the required python version is installed at a system level then, it will look for the .so in the wrong place. Perhaps it would make sense to put all pyenv compiled shared libraries together in the same folder, then either pyenv or the user can (temorarily) set LD_LIBRARY_PATH (not great) or the user can put e.g. ~/.pyenv/python_all/lib into ld.so.conf or the app get a system wide python assuming it exists.
LOL! - I had already provided a new answer to that very question on SE Those answers are what I expected. But that means spawning Btw: Somehow, on our pyenv installs I've raised an Issue #2649 that can be used to track a future PR on converting the hook script into a plugin as I've not got time to get into that right now. |
Pyenv installs alternate versions of software. Which means, any shared libraries it uses cannot be in the default module loading path lest they override system ones.
You can unset it right after loading. In this light, using an explicit path is probably a better idea.
Create a separate issue and provide the necessary diagnostic info for us to be able to say anything specific. Currently, I can only conjecture that you're passing |
Pyenv is designed to be able to provide machine-readable output for scripting. |
Pyenv is Bash-based. Thus even if we provided a C library, it would be doing exactly the same under the hood. So what's the point? |
Indeed, and I would agree bash powerful and a great shell, but sometimes the standard Linux command set + those embedded in bash are not enough when it comes to specific tasks. Yes it can do it, but it's not easy. There are many 'standard' tools that do essentially the same thing as a few extra lines in bash but that does not mean they should be deprecated. I would argue that not everybody in the world is a bash wizzard and that can it appear pyenv is lacking. For every one bash wizzard the are proably 100 Python programmers. Or to put it another way, by the same argument, if you have Python why do you need bash? |
I think we have strayed off topic. IIRC the task at hand was to link to the AFAICS, the most realistic way is to link with an explicit path: pp="$(pyenv prefix)"
p="${pp%%:*}" #if multiple versions are selected, `pyenv prefix' returns a colon-separated list
libpath="$(echo $p/lib/libpython*.*.so)"
<load $libpath> I gave the logic in Bash, but it can be replicated in any language. It seems pretty trivial to me. |
Give me a while to take a look at your suggestion as I am not working on this right now. |
I also am working on something else right now. The issues are with python-config, this tells the toolchain where to find the components of the current python. If a venv is active it seems to get it wrong. I'm still trying to work out how to make a CtoPython linked C program work all the time regardless of what env is active when a build is done and when it's used subsequently. Just reading about Ermine but that is commercial so I'd have to go through our legal team to consider it. It looks like a more lightweight Flatpack? I wonder if there is a more barebones method? Ermine is a tricky name to Google alternates for..... Given only one .so is needed, really I just need to divert dlopen for that file to a mmap file. Of course I am also playing with pyenv building for just static, but it seems not to always work. |
Some reproduction steps would certainly help (a sample program and what you're doing). |
Yep, I hear you. I am not able to work on the project being affected by pyenv right now as other work has pushed it to one side. I just found STATIFIER so mentioning it here so when I do get back onto this code I will not have forgotten about it. That may sidestep the issue completely - or will it. It says GPL which means if I statically link to any part of it my companies code has to be GPL, I don't think that will go down well..... For now you are right to close this one as I am unable to provide the detail needed. |
also |
For anyone else in 2024 on linux or something similar, who wants to use an older Python to do something like
Pyenv is a way forward. Without disrupting the Python system packages, one possible solution is #!/usr/bin/env bash
echo "Attempting to update the LD_LIBRARY_PATH to $(pyenv prefix)/lib"
pp=$(pyenv prefix)
echo "Note that \`pyenv prefix\` returns multiple colon-separated values if multiple versions are installed"
p="${pp%%:*}"
export LD_LIBRARY_PATH="$p/lib:$LD_LIBRARY_PATH"
and execute your shell's specific way of sourcing something new into it. In my case, I'm using zshell which operates similarly to bash. You next need to invoke: source source-me.sh Then you ought to be able to run Welcome to Swift version 5.10.1 (swift-5.10.1-RELEASE).
Type :help for assistance.
1> Cheers! |
I have an issue where I am writing C extensions to Python and calling Python from C.
If I run Python, it works fine within the env, but the C applications that embed the same Python code do not. I thought this was because the venv was compiled as static, so I enabled --enable-shared - see (gist). But even after doing that it still does not work.
I can now see this is because the apps lack a shim, and that is required to set/unset LD_LIBRARY_PATH.
But, managing a lot of apps, some user created using libraries we provide, across a lot of installs on thousands of systems will be problematic.
We have to use pyenv as (for complicated reasons) we have to support multiple python versions concurrently. We still support products that are 15+ years old at the same time as ones that don't oficially exist yet.
I started looking at setting LD_LIBRARY_PATH dynamically, from within the app, so that it detects if it's in a pyenv and choose the correct path before loading the matching version of the real application as an overlay.
My question is, what is a reliable, portable, low cost way for a compiled app to detect 1: if the current tree is within a venv, 2: if pyenv is installed and 3: if the required Python version is present in the library of versions, before 4: installing the required version itself.
activated
virtualenvs elsewhere (which is likely)Prerequisite
pyenv
and the defaultpython-build
plugin only. Please refrain from reporting issues of other plugins here.Description
env PYENV_DEBUG=1 <faulty command> 2>&1 | tee trace.log
and attachtrace.log
. E.g. if you have a problem with installing Python, runenv PYENV_DEBUG=1 pyenv install -v <version> 2>&1 | tee trace.log
(note the-v
option topyenv install
).config.log
from the build directory/tmp
.env PYENV_DEBUG=1 pyenv install -f -k -v <version> 2>&1 | tee trace.log
config.log
from the build directory. When usingpyenv install
with-k
as per above, the build directory will be under$PYENV_ROOT/sources
.The text was updated successfully, but these errors were encountered: