Repository: spack/spack

Issue:
Installation issue: gdb in Ubuntu 16.04.6, python from system
<!--*Thanks for taking the time to report this build failure. To proceed with the
report please:*
1. Title the issue "Installation issue: <name-of-the-package>".
2. Provide the information required below.

We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively!
-->


### Spack version
<!-- Add the output to the command below -->
```console
$ spack --version
0.14.1-355-3aa225cd5
```

### Steps to reproduce the issue

```console
$ spack spec gdb
Input spec
--------------------------------
gdb

Concretized
--------------------------------
gdb@9.1%gcc@9.2.0+python+xz arch=linux-ubuntu16.04-ivybridge
    ^python@2.7.12%gcc@9.2.0+bz2+ctypes+dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4~uuid+zlib arch=linux-ubuntu16.04-ivybridge
    ^texinfo@6.5%gcc@9.2.0 patches=12f6edb0c6b270b8c8dba2ce17998c580db01182d871ee32b7b6e4129bd1d23a,1732115f651cff98989cb0215d8f64da5e0f7911ebf0c13b064920f088f2ffe1 arch=linux-ubuntu16.04-ivybridge
        ^perl@5.30.1%gcc@9.2.0+cpanm+shared+threads arch=linux-ubuntu16.04-ivybridge
            ^gdbm@1.18.1%gcc@9.2.0 arch=linux-ubuntu16.04-ivybridge
                ^readline@8.0%gcc@9.2.0 arch=linux-ubuntu16.04-ivybridge
                    ^ncurses@6.2%gcc@9.2.0~symlinks+termlib arch=linux-ubuntu16.04-ivybridge
                        ^pkgconf@1.6.3%gcc@9.2.0 arch=linux-ubuntu16.04-ivybridge
    ^xz@5.2.5%gcc@9.2.0 arch=linux-ubuntu16.04-ivybridge

spack install gdb
...
==> 3235: gdb: Executing phase: 'autoreconf'
==> 3235: gdb: Executing phase: 'configure'
==> Error: RuntimeError: Unable to locate libpython2.7.so libraries in /usr/lib                                                                             

/home/hector/UT/Work/spack/var/spack/repos/builtin/packages/python/package.py:686, in libs:                                                                 
        683                return LibraryList(os.path.join(frameworkprefix, ldlibrary))                                                                     
        684            else:
        685                msg = 'Unable to locate {0} libraries in {1}'
  >>    686                raise RuntimeError(msg.format(ldlibrary, libdir))
        687        else:
        688            library = self.get_config_var('LIBRARY')
        689

See build log for details:
  /tmp/hector/spack-stage/spack-stage-gdb-9.1-dgri4c2byyy5yxiplemxa2q4r7yokuuf/spack-build-out.txt                                                          

==> Error: Failed to install gdb due to ChildError: RuntimeError: Unable to locate libpython2.7.so libraries in /usr/lib                                    
/home/hector/UT/Work/spack/var/spack/repos/builtin/packages/python/package.py:686, in libs:                                                                 
        683                return LibraryList(os.path.join(frameworkprefix, ldlibrary))                                                                     
        684            else:
        685                msg = 'Unable to locate {0} libraries in {1}'
  >>    686                raise RuntimeError(msg.format(ldlibrary, libdir))
        687        else:
        688            library = self.get_config_var('LIBRARY')
        689

See build log for details:
  /tmp/hector/spack-stage/spack-stage-gdb-9.1-dgri4c2byyy5yxiplemxa2q4r7yokuuf/spack-build-out.txt                                                          
Traceback (most recent call last):
  File "/home/hector/UT/Work/spack/lib/spack/spack/build_environment.py", line 801, in child_process                                                        
    return_value = function()
  File "/home/hector/UT/Work/spack/lib/spack/spack/installer.py", line 1113, in build_process                                                               
    phase(pkg.spec, pkg.prefix)
  File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/hector/UT/Work/spack/lib/spack/llnl/util/filesystem.py", line 605, in working_dir                                                             
    yield
  File "/home/hector/UT/Work/spack/lib/spack/spack/installer.py", line 1113, in build_process                                                               
    phase(pkg.spec, pkg.prefix)
  File "/home/hector/UT/Work/spack/lib/spack/spack/package.py", line 108, in phase_wrapper                                                                  
    phase(spec, prefix)
  File "/home/hector/UT/Work/spack/lib/spack/spack/build_systems/autotools.py", line 280, in configure                                                      
    options += self.configure_args()
  File "/home/hector/UT/Work/spack/var/spack/repos/builtin/packages/gdb/package.py", line 52, in configure_args                                             
    return args
  File "/home/hector/UT/Work/spack/lib/spack/spack/spec.py", line 868, in __get__                                                                           
    value = f()
  File "/home/hector/UT/Work/spack/lib/spack/spack/spec.py", line 857, in <lambda>                                                                          
    callbacks_chain.append(lambda: getattr(pkg, self.attribute_name))
  File "/home/hector/UT/Work/spack/var/spack/repos/builtin/packages/python/package.py", line 687, in libs                                                   
    else:
RuntimeError: Unable to locate libpython2.7.so libraries in /usr/lib
```

### Platform and user environment

<!-- Please report your OS here:
```commandline
$ uname -a 
Linux nuvolari 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -d
Description:	Ubuntu 18.04.1 LTS
``` 
and, if relevant, post or attach:

- `packages.yaml`
- `compilers.yaml`

to the issue
-->
```commandline
$ uname -a 
Linux bandera 4.15.0-88-generic #88~16.04.1-Ubuntu SMP Wed Feb 12 04:19:15 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -d
Description:    Ubuntu 16.04.6 LTS
``` 
relevant part of `packages.yaml`
```yaml
packages:
    python:
        paths:
            python@2.7.12: /usr/
        buildable: False
    gdb:
        variants: +python
```

### Additional information

<!--Sometimes the issue benefits from additional details. In these cases there are
a few things we can suggest doing. First of all, you can post the full output of:
```console
$ spack spec --install-status <spec>
...
```
to show people whether Spack installed a faulty software or if it was not able to
build it at all. 

If your build didn't make it past the configure stage, Spack as also commands to parse 
logs and report error and warning messages:
```console
$ spack log-parse --show=errors,warnings <file-to-parse>
```
You might want to run this command on the `config.log` or any other similar file
found in the stage directory: 
```console
$ spack location -s <spec>
```
In case in `config.log` there are other settings that you think might be the cause 
of the build failure, you can consider attaching the file to this issue.

Rebuilding the package with the following options:
```console
$ spack -d install -j 1 <spec>
...
```
will provide additional debug information. After the failure you will find two files in the current directory:

1. `spack-cc-<spec>.in`, which contains details on the command given in input 
    to Spack's compiler wrapper  
1. `spack-cc-<spec>.out`, which contains the command used to compile / link the 
    failed object after Spack's compiler wrapper did its processing 

You can post or attach those files to provide maintainers with more information on what
is causing the failure.-->

### General information

- [x] I have run `spack --version` and reported the version of Spack
- [x] I have searched the issues of this repo and believe this is not a duplicate



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py
--- a/var/spack/repos/builtin/packages/python/package.py
+++ b/var/spack/repos/builtin/packages/python/package.py
@@ -670,6 +670,11 @@ def libs(self):
         # to ask Python where its LIBDIR is.
         libdir = self.get_config_var('LIBDIR')
 
+        # In Ubuntu 16.04.6 and python 2.7.12 from the system, lib could be
+        # in LBPL
+        # https://mail.python.org/pipermail/python-dev/2013-April/125733.html
+        libpl = self.get_config_var('LIBPL')
+
         # The system Python installation on macOS and Homebrew installations
         # install libraries into a Frameworks directory
         frameworkprefix = self.get_config_var('PYTHONFRAMEWORKPREFIX')
@@ -679,6 +684,8 @@ def libs(self):
 
             if os.path.exists(os.path.join(libdir, ldlibrary)):
                 return LibraryList(os.path.join(libdir, ldlibrary))
+            elif os.path.exists(os.path.join(libpl, ldlibrary)):
+                return LibraryList(os.path.join(libpl, ldlibrary))
             elif os.path.exists(os.path.join(frameworkprefix, ldlibrary)):
                 return LibraryList(os.path.join(frameworkprefix, ldlibrary))
             else:


Test patch: