guettli
guettli

Reputation: 27969

virtualenv on Ubuntu symlink local/lib -> ../lib?

If I create a virtualenv on Ubuntu 16.04 (Python2), then a directory local gets created which contains symlinks:

===> virtualenv symlinktest
New python executable in /home/tguettler/tmp/symlinktest/bin/python
Please make sure you remove any previous custom paths from your /home/tguettler/.pydistutils.cfg file.
Installing setuptools, pip, wheel...done.



===> ls -l symlinktest/local/



===> ls -l symlinktest/local/*
lrwxrwxrwx 1 tguettler tguettler 35 Mär  7 14:21 symlinktest/local/bin -> /home/tguettler/tmp/symlinktest/bin
lrwxrwxrwx 1 tguettler tguettler 39 Mär  7 14:21 symlinktest/local/include -> /home/tguettler/tmp/symlinktest/include
lrwxrwxrwx 1 tguettler tguettler 35 Mär  7 14:21 symlinktest/local/lib -> /home/tguettler/tmp/symlinktest/lib


===> virtualenv --version
15.0.3

This does not happen on other linux distributions.

Why and where does this symlink get created?

Update

On this plattform openSUSE 42.1 (x86_64) a symlink from lib64 to lib gets created ...

I don't understand the need for this symlink.

Upvotes: 1

Views: 279

Answers (1)

nir0s
nir0s

Reputation: 1181

So, after prying into the virtualenv code just a tad, it seems that the following happens:

create_environment calls install_python which calls fix_local_scheme (https://github.com/pypa/virtualenv/blob/master/virtualenv.py#L1492). Note how in the docstring they state that this is needed for posix systems like Ubuntu with Python 2.7 (which you're running)

>>> import platform
>>> platform.linux_distribution()
('Ubuntu', '16.04', 'xenial')

$ python2.7
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig._get_default_scheme()
'posix_local'


$ cat /usr/lib/python2.7/sysconfig.py
def _get_default_scheme():
    if os.name == 'posix':
        # the default scheme for posix on Debian/Ubuntu is posix_local
        # FIXME: return dist-packages/posix_prefix only for
        #   is_default_prefix and 'PYTHONUSERBASE' not in os.environ and 'real_prefix' not in sys.__dict__
        # is_default_prefix = not prefix or os.path.normpath(prefix) in ('/usr', '/usr/local')
        return 'posix_local'
    return os.name

You can also read the explanation on the different prefixes: https://pymotw.com/2/sysconfig/#installation-paths, for more information.

Upvotes: 1

Related Questions