Skip to content
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

virtualenv should also copy shared libraries? #1015

Closed
woosley opened this issue Feb 8, 2017 · 20 comments
Closed

virtualenv should also copy shared libraries? #1015

woosley opened this issue Feb 8, 2017 · 20 comments

Comments

@woosley
Copy link

woosley commented Feb 8, 2017

see this patch for pyenv

pyenv/pyenv@2657f10

When compile python with '--enable-shared -Wl,-rpath='$$ORIGIN/../lib', the created python can be dropped to any folder.

But after virtualenv copy the python binary to a different folder, the relative path "bin/../lib" to libpython.so will be broken, the python binary will die with

/root/test/bin/python3.5: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory

In this case, virtualenv should also consider copy the shared object file to the new folder.

@yan12125
Copy link

yan12125 commented Feb 8, 2017

I've just installed pyenv and reverted pyenv/pyenv@afbd54d, but there's still no rpath set. How to install python with rpath?

@yyuu
Copy link

yyuu commented Feb 8, 2017

It'll set rpath if PYTHON_CONFIGURE_OPTS includes --enable-shared.

https://github.com/yyuu/pyenv/blob/master/plugins/python-build/bin/python-build#L1914

@yan12125
Copy link

yan12125 commented Feb 8, 2017

OK reproduced.

By the way, if you have no need on Python < 3.3, I suggest the standard venv library, which is much better in handling such cases.

@woosley
Copy link
Author

woosley commented Feb 9, 2017

I do need Python < 3.3.
What is the best approach for this issue? maybe an option --with-shared? if so, I can make a patch.

@yan12125
Copy link

yan12125 commented Feb 9, 2017

I bet it would be better to have things auto-detected.

@woosley
Copy link
Author

woosley commented Feb 17, 2017

this is a bit tricky
the only solid way to detect $ORIGIN is readelf

[root@maddog 2.7.9]# readelf -d  bin/python|grep  RPATH
 0x000000000000000f (RPATH)              Library rpath: [$ORIGIN/../lib]

I am wondering in what case this readelf will be not available

@yan12125
Copy link

IMO always copying libpython.so is the file is there sounds fine. But I'm not core virtualenv developer, and I don't have merge permissions. My opinions are definitely unreliable.

@gst
Copy link

gst commented May 10, 2017

Hi,

I'm in the need of this feature as well,

any idea when it might be applied / available ?

Thx.

@gst
Copy link

gst commented May 12, 2017

@woosley :

the only solid way to detect $ORIGIN is readelf

what about :

$ ~/.pythonz/pythons/CPython-2.7.12/bin/python -c "
import sysconfig
ldflags = sysconfig.get_config_var('LDFLAGS')
print
print ldflags
print '-rpath' in ldflags.split(',')"

-Wl,-rpath,'$'ORIGIN/../lib
True

?

@yan12125
Copy link

It's possible to change rpath via utilities like chrpath.

@gst
Copy link

gst commented May 15, 2017

@yan12125 : chrpath is not necessarily available when you execute virtualenv.
so I'd expect virtualenv to copy (or symlink) the necessary lib file (which must be present ofcourse) when it can detect that the python used to create a virtualenv has been compiled with such a setting/configuration.

@yan12125
Copy link

Sorry if I wasn't clear. What I wanted to say is that it's possible to use chrpath instead of LDFLAGS when building CPython, so detecting rpath from LDFLAGS is not reliable.

@gst
Copy link

gst commented May 15, 2017

Ah, I see.
well, it's maybe possible but isn't the recommanded way is to use LDFLAGS ? so that this quite important information is recorded and made available in/via the sysconfig module.. which is designed for this AFAIK ?

@yan12125
Copy link

Yep I believe almost all packagers use LDFLAGS. I'm not sure whether virtualenv should handle edge cases or not. I'm not a maintainer but just another random person who uses virtualenv often. Those are just my two cents :)

@woosley
Copy link
Author

woosley commented May 16, 2017

Unfortunately the maintainers have been silence for a while :(

@pfmoore
Copy link
Member

pfmoore commented May 16, 2017

Personally, I don't have the Unix skills to comment here, sorry.

But on the subject of edge cases, I will say that one person's edge case is another person's core usage, so I'd be reluctant to make a fix for one issue that could break other users. After all, the original issue here is just as much a non-standard build of Python as anything else.

From what I can understand of the original issue here, you're building a Python installation that is relocatable (i.e., you can copy it somewhere else). If that's the case, I'm not entirely sure why you even need virtualenv - instead of using virtualenv, just take another copy of your Python installation. Virtualenv is essentially a tool that creates a partial copy of "just enough" of the Python installation, and it's pretty fragile because core Python (prior to the introduction of the venv module didn't actually support doing this. So we keep hitting issues where distributions and/or projects like pyvenv make their own custom Python builds with changes that break our approach. It's hard to solve these issues without introducing other issues elsewhere.

@gst
Copy link

gst commented May 16, 2017

giving my 2 cents:

in any case : I think that copying that .so lib to the target virtualenv (under the usual lib directory) would not break anything which would otherwise correctly behaves actually. ofcourse that would have to be somehow validated (by some test case I guess).

@pfmoore for your remark : effectively copying a truly relocatable python installation could be all good here (though we would have to wipe out site-packages to be sure to start from a fresh/clean state). I agree.
But the fact is that : even if that can be, why couldn't it (that not so special python installation) be also usable with virtualenv (especially if all it needs to is to copy (or symlink) a single extra file) ?
The virtualenv has also the added advantage of defaulting to symlink for most files..

@woosley
Copy link
Author

woosley commented May 16, 2017

I agree with what @gst said.

  • I don't think it will break anything
  • there will be benifits in other cases if virtualenv can add this feature. For examaple, virtualenv comes with handy tool to activate and deactive the environments. If I just relocate the installation, I have to setup all those tools myself again.

@gst
Copy link

gst commented Jun 2, 2017

For any info :
I've updated the PR #1045 with little enh. (and added a test case).

@stale
Copy link

stale bot commented Jan 14, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just add a comment if you want to keep it open. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 14, 2019
@woosley woosley closed this as completed Jan 14, 2019
@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants