guettli
guettli

Reputation: 27969

virtualenv creates directory called 'local' on Ubuntu

If I create a virtualenv with Ubuntu 18.04, then a directory called local gets created.

virtualenv test-env
cd test-env
ls -l local/

Output:

lrwxrwxrwx 1 foo foo 30 Jan 30 10:47 bin -> /home/foo/tmp/test-env/bin
lrwxrwxrwx 1 foo foo 34 Jan 30 10:47 include -> /home/foo/tmp/test-env/include
lrwxrwxrwx 1 foo foo 30 Jan 30 10:47 lib -> /home/foo/tmp/test-env/lib

Version:

virtualenv --version
15.0.3

This does not happen on other machines (for example enterprise SuSE Linux)

AFAIK this directory is not needed.

Is there a way to avoid this directory called local which is not needed?

(This is about Python 2.7)

Upvotes: 2

Views: 1203

Answers (2)

shafikshaon
shafikshaon

Reputation: 6404

In Ubuntu virtualenv imitates the machine's installation, and local is part of that. If you want to ignore this in your project, you can add it to .gitignore

Upvotes: 3

hyperTrashPanda
hyperTrashPanda

Reputation: 868

Digging through the docs, and some older SO posts, I stumbled on this answer, and the official Release Notes.

On my Ubuntu 16.04 and virtualenv 15.0.1 combo, the ~/.local folder holds all Python-related libraries, documentation, and binaries.

I suspect that virtualenv is trying to "match" this approach, in order to retain compatibility with scripts run on the bare system, as the Python $PATH looks there for Python-related modules, packages, etc.

Python 2.7.12 (default, Dec  4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print '\n'.join(sys.path)

/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
...
/home/<username>/.local/lib/python2.7/site-packages
...
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages

If I run the same command inside my virtualenv, I get both directories in my Python path.

Python 2.7.12 (default, Dec  4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print '\n'.join(sys.path)

/home/<username>/python-venv-tests/lib/python2.7
/usr/lib/python2.7
...
/home/<username>/python-venv-tests/local/lib/python2.7/site-packages
/home/<username>/python-venv-tests/lib/python2.7/site-packages
...

So, to answer your question

  • This .local directory contains only symlinks to the 'proper' /bin, /include, /lib of your virtual environment, so there's no danger of duplicate libraries
  • This is most possibly done as a compatibility measure to Ubuntu using ~/.local for Python packages
  • This means you're free to delete this and/or change your Python $PATH if you really need to, but it will not have any impact on your workflow (or if you plan to migrate the virtual env to a different host).
  • Generally speaking, I'd suggest keeping it as-is, so that the virtual environment matches the system structure as much as possible, and that other scripts/users that may have hard-coded values depending on it avoid errors.

Upvotes: 7

Related Questions