Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,10 @@ Linker options
a different directory name for the standard library, but not a nested path.
On Linux, these paths use ``DT_RPATH``.

Copied virtual environments from non-framework shared builds require
directory symlinks to the base installation's libraries. Virtual environments
depend on their base installation and must be recreated if it moves.

Dependencies stored in other directories, such as ``lib/tcltk``, may
need additional loader search paths.

Expand Down
9 changes: 8 additions & 1 deletion Lib/test/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,9 @@ def test_zippath_from_non_installed_posix(self):
# LD_LIBRARY_PATH so the non-installed python can find and link
# libpython.so
ld_library_path = sysconfig.get_config_var("LIBDIR")
if (sysconfig.get_config_var("RELOCATABLE") == "yes"
and not sysconfig.get_config_var("PYTHONFRAMEWORK")):
ld_library_path = os.path.join(sys.base_exec_prefix, "lib")
if not ld_library_path or sysconfig.is_python_build():
ld_library_path = os.path.abspath(os.path.dirname(sys.executable))
if sys.platform == 'darwin':
Expand All @@ -1154,7 +1157,11 @@ def test_zippath_from_non_installed_posix(self):
# correct zip path in pythonpath.
target_python = os.path.join(self.env_dir, self.bindir, python_exe)
cmd = [target_python, '-S', '-c', 'import sys; print(sys.path)']
out, err = check_output(cmd)
# This interpreter also depends on libraries outside the incomplete
# installation used by this test.
with EnvironmentVarGuard() as env:
env[ld_library_path_env] = ld_library_path
out, err = check_output(cmd)
self.assertTrue(zip_landmark.encode() in out)

@requireVenvCreate
Expand Down
14 changes: 14 additions & 0 deletions Lib/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,20 @@ def setup_python(self, context):
copier(context.executable, path)
if not os.path.islink(path):
os.chmod(path, 0o755)
if (sysconfig.get_config_var('RELOCATABLE') == 'yes'
and sysconfig.get_config_var('Py_ENABLE_SHARED')
and not sysconfig.get_config_var('PYTHONFRAMEWORK')):
# The copied executable searches relative to this environment.
# Link the base library directory so it can find libpython.
if sysconfig.is_python_build():
library_dir = context.python_dir
else:
library_dir = os.path.join(sys.base_exec_prefix, 'lib')
library_link = os.path.join(
context.env_dir, 'lib', 'python-base')
if os.path.islink(library_link):
os.unlink(library_link)
os.symlink(library_dir, library_link, target_is_directory=True)
for suffix in ('python', 'python3',
f'python3.{sys.version_info[1]}'):
path = os.path.join(binpath, suffix)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Support copied virtual environments from non-framework shared builds configured
with :option:`--enable-relocatable` by linking the base library directory into
the environment. Copied environments require filesystem support for directory
symlinks.
4 changes: 2 additions & 2 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6901,7 +6901,7 @@ AS_IF([test "$enable_relocatable" = yes && test -z "$enable_framework"], [
[Linux], [
# Keep the dollar sign through configure, make, and the shell.
# DT_RPATH entries can also resolve indirect dependencies.
RELOCATABLE_PYTHON_LDFLAGS="-Wl,--disable-new-dtags,-rpath,'\$\$ORIGIN/../lib'"
RELOCATABLE_PYTHON_LDFLAGS="-Wl,--disable-new-dtags,-rpath,'\$\$ORIGIN/../lib:\$\$ORIGIN/../lib/python-base'"
RELOCATABLE_LIBPYTHON_LDFLAGS="-Wl,--disable-new-dtags,-rpath,'\$\$ORIGIN'"
RELOCATABLE_EXTENSION_LDFLAGS="-Wl,--disable-new-dtags,-rpath,'\$\$ORIGIN/../../../lib'"
save_LDFLAGS=$LDFLAGS
Expand All @@ -6912,7 +6912,7 @@ AS_IF([test "$enable_relocatable" = yes && test -z "$enable_framework"], [
],
[Darwin], [
RELOCATABLE_LIBPYTHON_INSTALL_NAME='@rpath/libpython$(LDVERSION).dylib'
RELOCATABLE_PYTHON_LDFLAGS='-Wl,-rpath,@executable_path/../lib'
RELOCATABLE_PYTHON_LDFLAGS='-Wl,-rpath,@executable_path/../lib -Wl,-rpath,@executable_path/../lib/python-base'
RELOCATABLE_LIBPYTHON_LDFLAGS='-Wl,-rpath,@loader_path'
RELOCATABLE_EXTENSION_LDFLAGS='-Wl,-rpath,@loader_path/../../../lib'
])
Expand Down
Loading