Skip to content

pip install virtualenv embeds absolute path to Python interpreter #5048

@jameshfisher

Description

@jameshfisher

Pip version:

$ pip --version
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)

Python version:

$ python --version
Python 2.7.14
$ which python
/usr/local/opt/python@2/libexec/bin/python

Operating system: macOS 10.13.3

Description:

This morning, when I ran virtualenv, I got this:

$ virtualenv
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory

virtualenv only started behaving this way today. It worked yesterday. It broke because virtualenv is a Python script which embeds the absolute path to a Python interpreter which went away:

$ which virtualenv
/usr/local/bin/virtualenv
$ head -1 /usr/local/bin/virtualenv
#!/usr/local/opt/python/bin/python2.7

It appears that this absolute path is generated dynamically! After pip uninstall virtualenv && pipinstall virtualenv, I get a new absolute path to a new Python interpreter:

$ head -1 /usr/local/bin/virtualenv
#!/usr/local/opt/python@2/bin/python2.7

This behavior is not idiomatic, and causes pip-installed packages to break in confusing ways when the path to the interpreter changes!

The idiomatic behavior is for virtualenv to resolve Python from my PATH at runtime, not at install time. For example, the script could begin with a portable interpreter command, e.g. #!/usr/bin/env python. Why is this not the case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions