Repository: pypa/pip

Issue:
ValueError while unpacking platform.mac_ver() on OS X 10.11
on Travis `osx10.11` image, I am getting `ValueError` while trying to run `python get-pip.py --user` with El Capitan's built-in python 2.7.10:

```
Traceback (most recent call last):
  File "get-pip.py", line 19000, in <module>
    main()
  File "get-pip.py", line 179, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    import pip
  File "/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/tmpZ_zMd5/pip.zip/pip/__init__.py", line 15, in <module>
  File "/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/tmpZ_zMd5/pip.zip/pip/vcs/subversion.py", line 9, in <module>
  File "/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/tmpZ_zMd5/pip.zip/pip/index.py", line 29, in <module>
  File "/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/tmpZ_zMd5/pip.zip/pip/wheel.py", line 32, in <module>
  File "/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/tmpZ_zMd5/pip.zip/pip/pep425tags.py", line 214, in <module>
  File "/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/tmpZ_zMd5/pip.zip/pip/pep425tags.py", line 162, in get_supported
  File "/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/tmpZ_zMd5/pip.zip/pip/pep425tags.py", line 119, in get_platform
ValueError: need more than 2 values to unpack
```

Full log here: https://travis-ci.org/behdad/fonttools/jobs/103554883

I think it's because of this commit:
https://github.com/pypa/pip/commit/995deff93977fbb85d07df3e4c15388f0f0140e2

It looks like `platform.mac_ver()` doesn't always return a tuple of 3 elements, but sometimes only 2...



Discussion:
Yep.

``` python
python -c 'import platform; print platform.mac_ver()'
('10.11', ('', '', ''), 'x86_64')
```

https://travis-ci.org/anthrotype/fonttools/jobs/103565174#L1444

/cc @rmcgibbo

I encountered the issue during an uninstall command. If anybody needs a quick fix, open `site-packages/pip/pep425tags.py`, head to line 118, and change `get_platform()` to something like:

``` python
def get_platform():
    """Return our platform name 'win32', 'linux_x86_64'"""
    if sys.platform == 'darwin':
        # distutils.util.get_platform() returns the release based on the value
        # of MACOSX_DEPLOYMENT_TARGET on which Python was built, which may
        # be signficantly older than the user's current machine.
        release, _, machine = platform.mac_ver()
        split_ver = release.split('.')
        return 'macosx_{0}_{1}_{2}'.format(split_ver[0], split_ver[1], machine)
    # XXX remove distutils dependency
    return distutils.util.get_platform().replace('.', '_').replace('-', '_')
```

Worked for me!


Resolving patch:
diff --git a/pip/pep425tags.py b/pip/pep425tags.py
--- a/pip/pep425tags.py
+++ b/pip/pep425tags.py
@@ -116,8 +116,8 @@ def get_platform():
         # of MACOSX_DEPLOYMENT_TARGET on which Python was built, which may
         # be signficantly older than the user's current machine.
         release, _, machine = platform.mac_ver()
-        major, minor, micro = release.split('.')
-        return 'macosx_{0}_{1}_{2}'.format(major, minor, machine)
+        split_ver = release.split('.')
+        return 'macosx_{0}_{1}_{2}'.format(split_ver[0], split_ver[1], machine)
     # XXX remove distutils dependency
     return distutils.util.get_platform().replace('.', '_').replace('-', '_')
 


Test patch: