This is perfectly fine, this is how the console scripts for entry points are generated. Of course there are the limitations that files and directories can not be renamed, etc. but well that is quite obvious.
For example here is the content of the pip
script in a freshly created virtual environment:
/tmp/tmp.cqz22j4Vg7$ cat .venv/bin/pip
#!/tmp/tmp.cqz22j4Vg7/.venv/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
I believe the shebang in the scripts is an absolute path exactly so that they can be called without having to activate the virtual environment.
A common practice is to keep such a virtual environment around and add a symbolic link to a particular script in a directory listed in PATH
. For example, one could install tox in a virtual environment and make it available from anywhere:
ln -s '/path/to/venv/bin/tox' "${HOME}/.local/bin/tox"
From Python's venv documentation:
There should be no need in other circumstances to activate a virtual environment; scripts installed into virtual environments have a “shebang” line which points to the virtual environment’s Python interpreter.
-- https://docs.python.org/3/library/venv.html?highlight=shebang