Skip to content

python: PYTHONHOME may not be the same as the prefix of the python ex…#2173

Merged
tgamblin merged 1 commit intospack:developfrom
BarrySmith:barry/fix-pythonhome
Oct 31, 2016
Merged

python: PYTHONHOME may not be the same as the prefix of the python ex…#2173
tgamblin merged 1 commit intospack:developfrom
BarrySmith:barry/fix-pythonhome

Conversation

@BarrySmith
Copy link
Copy Markdown
Contributor

…ecutable

On MacOS, brew installs /usr/local/bin/python but the Python prefix is not /usr/local/bin
Use the python command sys.exec to get the correct directory, instead of the ad hoc self.prefix
previously used

This was a bear to debug; been driving me nuts since I started using spack.
Since spack passes PYTHONHOME down to package builds in the environment
it was passing PYTHONHOME of /usr/local/bin to the PETSc build that uses Python so
the PETSc Python ./configure errored immediately with

ImportError: No module named site

since python could find no python modules

Funded-by: IDEAS
Project: IDEAS/xSDK
Time: 6 hours

@tgamblin
Copy link
Copy Markdown
Member

@BarrySmith: I don't think this is quite right either. This gets the sys.prefix of the Python that's running Spack, but the Python package in Spack can be executed either on behalf of that Python or a spack-installed Python. I'm assuming you've put an external python in packages.yaml and you've set its prefix to /usr/local, and that is why this isn't working for you? Is that right?

Also was Spack using /usr/local as the prefix or /usr/local/bin?

Two questions:

  1. Why shouldn't we just recommend people to use Homebrew's Cellar for this, and have them set the prefix in packages.yaml to, e.g., `/usr/local/Cellar/python/2.7.12_2', which is actually the prefix?

  2. Alternately, I guess you could do this:

    python = Executable(os.path.join(self.prefix.bin, 'python'))
    prefix = python('-c', 'import sys; print(sys.prefix)', output=str)
    spack_env.set('PYTHONHOME', prefix)

    This would always get the prefix from the python the spec describes...

I am not sure that (2) works in all cases. In particular, looking at how Homebrew installs Python I'm not sure what we can assume about /usr/local for an external Homebrew python. It seems like it only links a very small part of the directory structure:

(atala):~$ brew link --dry-run python
Would link:
/usr/local/bin/2to3
/usr/local/bin/2to3-2
/usr/local/bin/2to3-2.7
/usr/local/bin/easy_install
/usr/local/bin/easy_install-2.7
/usr/local/bin/idle
/usr/local/bin/idle2
/usr/local/bin/idle2.7
/usr/local/bin/pip
/usr/local/bin/pip2
/usr/local/bin/pip2.7
/usr/local/bin/pydoc
/usr/local/bin/pydoc2
/usr/local/bin/pydoc2.7
/usr/local/bin/python
/usr/local/bin/python-config
/usr/local/bin/python2
/usr/local/bin/python2-config
/usr/local/bin/python2.7
/usr/local/bin/python2.7-config
/usr/local/bin/pythonw
/usr/local/bin/pythonw2
/usr/local/bin/pythonw2.7
/usr/local/bin/smtpd.py
/usr/local/bin/smtpd2.7.py
/usr/local/bin/smtpd2.py
/usr/local/bin/wheel
/usr/local/share/man/man1/python.1
/usr/local/share/man/man1/python2.1
/usr/local/share/man/man1/python2.7.1
/usr/local/share/python
/usr/local/lib/pkgconfig/python-2.7.pc
/usr/local/lib/pkgconfig/python.pc
/usr/local/lib/pkgconfig/python2.pc
/usr/local/Frameworks/Python.framework/Headers
/usr/local/Frameworks/Python.framework/Python
/usr/local/Frameworks/Python.framework/Resources
/usr/local/Frameworks/Python.framework/Versions/2.7
/usr/local/Frameworks/Python.framework/Versions/Current

Whereas the Python prefix in the Cellar is much more extensive. I am curious what would happen if you tried to spack activate a python package built with an external python -- we may not have that wired quite right.

@BarrySmith
Copy link
Copy Markdown
Contributor Author

Why shouldn't we just recommend people to use Homebrew's Cellar for this, and have them set the prefix in packages.yaml to, e.g., `/usr/local/Cellar/python/2.7.12_2', which is actually the prefix?

Users don't read documentation, simple things should just work

Alternately, I guess you could do this:

python = Executable(os.path.join(self.prefix.bin, 'python'))
prefix = python('-c', 'import sys; print(sys.prefix)', output=str)
spack_env.set('PYTHONHOME', prefix)

I will update the pull request with your second suggestion (I checked that it works (with a few fixes)) in a few minutes. Any python code that needs to know about the python directory and uses the properly sys.exec or sys.exec_prefix works fine with the brew python install (even without all the directories in /usr/local) it is only tools that incorrectly think the python executable has to be carefully located in the big python directory tree that don't work properly :-) Note that the Apply python does this same thing of having most of the directory tree off in some other directory.

But why are you even setting PYTHONHOME? Any properly installed Python should not need PYTHONHOME. Just don't set it and my problem goes away without complicated fixes.

@tgamblin
Copy link
Copy Markdown
Member

I believe we set it because setuptools and some other packages (maybe PyQt or PySide) wanted it. If we had more extensive package testing, I could recommend removing it but maybe we should wait until then to rip it out and see what breaks.

@tgamblin
Copy link
Copy Markdown
Member

@BarrySmith: flake8

@BarrySmith
Copy link
Copy Markdown
Contributor Author

@BarrySmith: flake8

Fixed

extension and any other python extensions it depends on."""
pythonhome = self.prefix
spack_env.set('PYTHONHOME', pythonhome)
python = Executable(os.path.join(self.prefix, 'python'))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break for Python3. We need to find another way...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In setup_dependent_package(), we use syntax like:

'python{0}'.format('3' if self.spec.satisfies('@3') else '')

This could easily be used here too. I wonder if we can make it a more generic property.

@citibeth
Copy link
Copy Markdown
Member

This PR makes me uneasy because, whatever problem it solves, the fix will not work for python@3: --- where the executable is called python3, not python.

@BarrySmith
Copy link
Copy Markdown
Contributor Author

This PR makes me uneasy because, whatever problem it solves, the fix will not work for python@3: --- where the executable is called python3, not python.

Good point. The PR could check for the existence of python or python3 at that location and if only one of the two exists then use it; but that doesn't help if there are both files there. Note that in my packages.yaml file I have

    python:
        paths:
            [email protected]: /usr/local/bin
        buildable: False

That is I don't indicate if the binary should be python or python3; is there a way for me to indicate that (based on the path how do you pick which one to use?)? And if I could list the executable then this information must be stored somewhere so couldn't it get pulled out of where it is stored and used here to select the correct binary?

@davydden
Copy link
Copy Markdown
Member

I don't indicate if the binary should be python or python3

IMHO you do by specifying version [email protected]

@BarrySmith
Copy link
Copy Markdown
Contributor Author

IMHO you do by specifying version [email protected]

Oh right, so I could possibly set python vs python3 based on the version information. Is python3 used for python version 3+ on all systems or do you have in spack someway a routine to map from version number to python3 based on the system (you must if you can determine the version to use from the python@version in the packages file)? Thanks

@davydden
Copy link
Copy Markdown
Member

I am not a python user, but i think the code above by @adamjstewart choose python3 for version 3 and above, and python otherwise. I would try that first.

@citibeth
Copy link
Copy Markdown
Member

If you download python.tar.gz from the Python website and build it, then
you will get python3 and no python if you downloaded version 3 or
greater. If you dowloaded version 2, I BELIEVE (but you should check) that
you will get python and python2.

Various system installations fiddle with this convention. MacOS Python is
v2 but has no python2 binary. Some installations install Python3 as
python.

If you know you're looking at a Spack-installed Python, then you can assume
that it's a standard build (since that's what python/package.py) does.
In that case, I'd rely on the version number and either look for python3
or python2.

If you're looking at any old random Python installation, you will have to
be a bit more clever. I would root around for the binaries python2,
python3 and python. If you find a python2 then use it and assume you
have Python v2. If you find a python3, use that and assume you have
Python v3. If you find both, throw an exception. If you find python and
no python2 or python3, then you will have to run it to figure out which
version you have on your hands.

I would not assume you're looking at a Spack-installed Python: users could
have specified an external Python in their packages.yaml file.

On Sun, Oct 30, 2016 at 1:01 PM, Denis Davydov [email protected]
wrote:

I am not a python user, but i think the code above by @adamjstewart
https://github.com/adamjstewart choose python3 for version 3 and above,
and python otherwise. I would try that first.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#2173 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AB1cdz7xjEc5vWMAbzQLDk3lv9ZSpgQtks5q5M1zgaJpZM4KkPQg
.

…ecutable

On MacOS, brew installs /usr/local/bin/python but the Python prefix is not /usr/local/bin
Use the python command sys.exec to get the correct directory, instead of the ad hoc self.prefix
previously used

This was a bear to debug; been driving me nuts since I started using spack.
Since spack passes PYTHONHOME down to package builds in the environment
it was passing PYTHONHOME of /usr/local/bin to the PETSc build that uses Python so
the PETSc Python ./configure errored immediately with

ImportError: No module named site

since python could find no python modules. Todd Gamblin pointed out that my first try to fix
this was wrong since it assumed the spack python was the same python used to run spack. Elizabeth Fischer
suggested how to get it to work also with python3

Funded-by: IDEAS
Project: IDEAS/xSDK
Time:  7 hours
Thanks-to: Todd Gamblin, Elizabeth Fischer
@BarrySmith
Copy link
Copy Markdown
Contributor Author

This PR makes me uneasy because, whatever problem it solves, the fix will not work for python@3: --- where the executable is called python3, not python.

@citibeth Updated to resolve the python3 issue

@citibeth
Copy link
Copy Markdown
Member

Thanks!

On Sun, Oct 30, 2016 at 6:12 PM, Barry Smith [email protected]
wrote:

This PR makes me uneasy because, whatever problem it solves, the fix will
not work for python@3: --- where the executable is called python3, not
python.

@citibeth https://github.com/citibeth Updated to resolve the python3
issue


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#2173 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AB1cd7KsQK44TXE0By2maFe57RfZu51Cks5q5RZYgaJpZM4KkPQg
.

@tgamblin
Copy link
Copy Markdown
Member

@citibeth can you approve the changes so I don't have to dismiss your review?

@citibeth
Copy link
Copy Markdown
Member

Oh sorry, I didn't realize that requesting changes on the new GitHub review feature came with responsibilities...

@tgamblin tgamblin merged commit a714377 into spack:develop Oct 31, 2016
pramodk added a commit to pramodk/spack that referenced this pull request Nov 16, 2016
…ython executable (spack#2173)"

This is to avoid issue reported here: spack#2208

This reverts commit a714377.
tgamblin pushed a commit that referenced this pull request Apr 30, 2017
## Motivation

Python installations are both important and unfortunately inconsistent. Depending on the Python version, OS, and the strength of the Earth's magnetic field when it was installed, the name of the Python executable, directory containing its libraries, library names, and the directory containing its headers can vary drastically. 

I originally got into this mess with #3274, where I discovered that Boost could not be built with Python 3 because the executable is called `python3` and we were telling it to use `python`. I got deeper into this mess when I started hacking on #3140, where I discovered just how difficult it is to find the location and name of the Python libraries and headers.

Currently, half of the packages that depend on Python and need to know this information jump through hoops to determine the correct information. The other half are hard-coded to use `python`, `spec['python'].prefix.lib`, and `spec['python'].prefix.include`. Obviously, none of these packages would work for Python 3, and there's no reason to duplicate the effort. The Python package itself should contain all of the information necessary to use it properly. This is in line with the recent work by @alalazo and @davydden with respect to `spec['blas'].libs` and friends.

## Prefix

For most packages in Spack, we assume that the installation directory is `spec['python'].prefix`. This generally works for anything installed with Spack, but gets complicated when we include external packages. Python is a commonly used external package (it needs to be installed just to run Spack). If it was installed with Homebrew, `which python` would return `/usr/local/bin/python`, and most users would erroneously assume that `/usr/local` is the installation directory. If you peruse through #2173, you'll immediately see why this is not the case. Homebrew actually installs Python in `/usr/local/Cellar/python/2.7.12_2` and symlinks the executable to `/usr/local/bin/python`. `PYTHONHOME` (and presumably most things that need to know where Python is installed) needs to be set to the actual installation directory, not `/usr/local`.

Normally I would say, "sounds like user error, make sure to use the real installation directory in your `packages.yaml`". But I think we can make a special case for Python. That's what we decided in #2173 anyway. If we change our minds, I would be more than happy to simplify things.

To solve this problem, I created a `spec['python'].home` attribute that works the same way as `spec['python'].prefix` but queries Python to figure out where it was actually installed. @tgamblin Is there any way to overwrite `spec['python'].prefix`? I think it's currently immutable.

## Command

In general, Python 2 comes with both `python` and `python2` commands, while Python 3 only comes with a `python3` command. But this is up to the OS developers. For example, `/usr/bin/python` on Gentoo is actually Python 3. Worse yet, if someone is using an externally installed Python, all 3 commands may exist in the same directory! Here's what I'm thinking:

If the spec is for Python 3, try searching for the `python3` command.
If the spec is for Python 2, try searching for the `python2` command.
If neither are found, try searching for the `python` command.

## Libraries

Spack installs Python libraries in `spec['python'].prefix.lib`. Except on openSUSE 13, where it installs to `spec['python'].prefix.lib64` (see #2295 and #2253). On my CentOS 6 machine, the Python libraries are installed in `/usr/lib64`. Both need to work.

The libraries themselves change name depending on OS and Python version. For Python 2.7 on macOS, I'm seeing:
```
lib/libpython2.7.dylib
```
For Python 3.6 on CentOS 6, I'm seeing:
```
lib/libpython3.so
lib/libpython3.6m.so.1.0
lib/libpython3.6m.so -> lib/libpython3.6m.so.1.0
```
Notice the `m` after the version number. Yeah, that's a thing.

## Headers

In Python 2.7, I'm seeing:
```
include/python2.7/pyconfig.h
```
In Python 3.6, I'm seeing:
```
include/python3.6m/pyconfig.h
```
It looks like all Python 3 installations have this `m`. Tested with Python 3.2 and 3.6 on macOS and CentOS 6

Spack has really nice support for libraries (`find_libraries` and `LibraryList`), but nothing for headers. Fixed.
diaena pushed a commit to diaena/spack that referenced this pull request May 26, 2017
## Motivation

Python installations are both important and unfortunately inconsistent. Depending on the Python version, OS, and the strength of the Earth's magnetic field when it was installed, the name of the Python executable, directory containing its libraries, library names, and the directory containing its headers can vary drastically. 

I originally got into this mess with spack#3274, where I discovered that Boost could not be built with Python 3 because the executable is called `python3` and we were telling it to use `python`. I got deeper into this mess when I started hacking on spack#3140, where I discovered just how difficult it is to find the location and name of the Python libraries and headers.

Currently, half of the packages that depend on Python and need to know this information jump through hoops to determine the correct information. The other half are hard-coded to use `python`, `spec['python'].prefix.lib`, and `spec['python'].prefix.include`. Obviously, none of these packages would work for Python 3, and there's no reason to duplicate the effort. The Python package itself should contain all of the information necessary to use it properly. This is in line with the recent work by @alalazo and @davydden with respect to `spec['blas'].libs` and friends.

## Prefix

For most packages in Spack, we assume that the installation directory is `spec['python'].prefix`. This generally works for anything installed with Spack, but gets complicated when we include external packages. Python is a commonly used external package (it needs to be installed just to run Spack). If it was installed with Homebrew, `which python` would return `/usr/local/bin/python`, and most users would erroneously assume that `/usr/local` is the installation directory. If you peruse through spack#2173, you'll immediately see why this is not the case. Homebrew actually installs Python in `/usr/local/Cellar/python/2.7.12_2` and symlinks the executable to `/usr/local/bin/python`. `PYTHONHOME` (and presumably most things that need to know where Python is installed) needs to be set to the actual installation directory, not `/usr/local`.

Normally I would say, "sounds like user error, make sure to use the real installation directory in your `packages.yaml`". But I think we can make a special case for Python. That's what we decided in spack#2173 anyway. If we change our minds, I would be more than happy to simplify things.

To solve this problem, I created a `spec['python'].home` attribute that works the same way as `spec['python'].prefix` but queries Python to figure out where it was actually installed. @tgamblin Is there any way to overwrite `spec['python'].prefix`? I think it's currently immutable.

## Command

In general, Python 2 comes with both `python` and `python2` commands, while Python 3 only comes with a `python3` command. But this is up to the OS developers. For example, `/usr/bin/python` on Gentoo is actually Python 3. Worse yet, if someone is using an externally installed Python, all 3 commands may exist in the same directory! Here's what I'm thinking:

If the spec is for Python 3, try searching for the `python3` command.
If the spec is for Python 2, try searching for the `python2` command.
If neither are found, try searching for the `python` command.

## Libraries

Spack installs Python libraries in `spec['python'].prefix.lib`. Except on openSUSE 13, where it installs to `spec['python'].prefix.lib64` (see spack#2295 and spack#2253). On my CentOS 6 machine, the Python libraries are installed in `/usr/lib64`. Both need to work.

The libraries themselves change name depending on OS and Python version. For Python 2.7 on macOS, I'm seeing:
```
lib/libpython2.7.dylib
```
For Python 3.6 on CentOS 6, I'm seeing:
```
lib/libpython3.so
lib/libpython3.6m.so.1.0
lib/libpython3.6m.so -> lib/libpython3.6m.so.1.0
```
Notice the `m` after the version number. Yeah, that's a thing.

## Headers

In Python 2.7, I'm seeing:
```
include/python2.7/pyconfig.h
```
In Python 3.6, I'm seeing:
```
include/python3.6m/pyconfig.h
```
It looks like all Python 3 installations have this `m`. Tested with Python 3.2 and 3.6 on macOS and CentOS 6

Spack has really nice support for libraries (`find_libraries` and `LibraryList`), but nothing for headers. Fixed.
xavierandrade pushed a commit to xavierandrade/spack that referenced this pull request Jun 16, 2017
## Motivation

Python installations are both important and unfortunately inconsistent. Depending on the Python version, OS, and the strength of the Earth's magnetic field when it was installed, the name of the Python executable, directory containing its libraries, library names, and the directory containing its headers can vary drastically. 

I originally got into this mess with spack#3274, where I discovered that Boost could not be built with Python 3 because the executable is called `python3` and we were telling it to use `python`. I got deeper into this mess when I started hacking on spack#3140, where I discovered just how difficult it is to find the location and name of the Python libraries and headers.

Currently, half of the packages that depend on Python and need to know this information jump through hoops to determine the correct information. The other half are hard-coded to use `python`, `spec['python'].prefix.lib`, and `spec['python'].prefix.include`. Obviously, none of these packages would work for Python 3, and there's no reason to duplicate the effort. The Python package itself should contain all of the information necessary to use it properly. This is in line with the recent work by @alalazo and @davydden with respect to `spec['blas'].libs` and friends.

## Prefix

For most packages in Spack, we assume that the installation directory is `spec['python'].prefix`. This generally works for anything installed with Spack, but gets complicated when we include external packages. Python is a commonly used external package (it needs to be installed just to run Spack). If it was installed with Homebrew, `which python` would return `/usr/local/bin/python`, and most users would erroneously assume that `/usr/local` is the installation directory. If you peruse through spack#2173, you'll immediately see why this is not the case. Homebrew actually installs Python in `/usr/local/Cellar/python/2.7.12_2` and symlinks the executable to `/usr/local/bin/python`. `PYTHONHOME` (and presumably most things that need to know where Python is installed) needs to be set to the actual installation directory, not `/usr/local`.

Normally I would say, "sounds like user error, make sure to use the real installation directory in your `packages.yaml`". But I think we can make a special case for Python. That's what we decided in spack#2173 anyway. If we change our minds, I would be more than happy to simplify things.

To solve this problem, I created a `spec['python'].home` attribute that works the same way as `spec['python'].prefix` but queries Python to figure out where it was actually installed. @tgamblin Is there any way to overwrite `spec['python'].prefix`? I think it's currently immutable.

## Command

In general, Python 2 comes with both `python` and `python2` commands, while Python 3 only comes with a `python3` command. But this is up to the OS developers. For example, `/usr/bin/python` on Gentoo is actually Python 3. Worse yet, if someone is using an externally installed Python, all 3 commands may exist in the same directory! Here's what I'm thinking:

If the spec is for Python 3, try searching for the `python3` command.
If the spec is for Python 2, try searching for the `python2` command.
If neither are found, try searching for the `python` command.

## Libraries

Spack installs Python libraries in `spec['python'].prefix.lib`. Except on openSUSE 13, where it installs to `spec['python'].prefix.lib64` (see spack#2295 and spack#2253). On my CentOS 6 machine, the Python libraries are installed in `/usr/lib64`. Both need to work.

The libraries themselves change name depending on OS and Python version. For Python 2.7 on macOS, I'm seeing:
```
lib/libpython2.7.dylib
```
For Python 3.6 on CentOS 6, I'm seeing:
```
lib/libpython3.so
lib/libpython3.6m.so.1.0
lib/libpython3.6m.so -> lib/libpython3.6m.so.1.0
```
Notice the `m` after the version number. Yeah, that's a thing.

## Headers

In Python 2.7, I'm seeing:
```
include/python2.7/pyconfig.h
```
In Python 3.6, I'm seeing:
```
include/python3.6m/pyconfig.h
```
It looks like all Python 3 installations have this `m`. Tested with Python 3.2 and 3.6 on macOS and CentOS 6

Spack has really nice support for libraries (`find_libraries` and `LibraryList`), but nothing for headers. Fixed.
EmreAtes pushed a commit to EmreAtes/spack that referenced this pull request Jul 10, 2017
## Motivation

Python installations are both important and unfortunately inconsistent. Depending on the Python version, OS, and the strength of the Earth's magnetic field when it was installed, the name of the Python executable, directory containing its libraries, library names, and the directory containing its headers can vary drastically. 

I originally got into this mess with spack#3274, where I discovered that Boost could not be built with Python 3 because the executable is called `python3` and we were telling it to use `python`. I got deeper into this mess when I started hacking on spack#3140, where I discovered just how difficult it is to find the location and name of the Python libraries and headers.

Currently, half of the packages that depend on Python and need to know this information jump through hoops to determine the correct information. The other half are hard-coded to use `python`, `spec['python'].prefix.lib`, and `spec['python'].prefix.include`. Obviously, none of these packages would work for Python 3, and there's no reason to duplicate the effort. The Python package itself should contain all of the information necessary to use it properly. This is in line with the recent work by @alalazo and @davydden with respect to `spec['blas'].libs` and friends.

## Prefix

For most packages in Spack, we assume that the installation directory is `spec['python'].prefix`. This generally works for anything installed with Spack, but gets complicated when we include external packages. Python is a commonly used external package (it needs to be installed just to run Spack). If it was installed with Homebrew, `which python` would return `/usr/local/bin/python`, and most users would erroneously assume that `/usr/local` is the installation directory. If you peruse through spack#2173, you'll immediately see why this is not the case. Homebrew actually installs Python in `/usr/local/Cellar/python/2.7.12_2` and symlinks the executable to `/usr/local/bin/python`. `PYTHONHOME` (and presumably most things that need to know where Python is installed) needs to be set to the actual installation directory, not `/usr/local`.

Normally I would say, "sounds like user error, make sure to use the real installation directory in your `packages.yaml`". But I think we can make a special case for Python. That's what we decided in spack#2173 anyway. If we change our minds, I would be more than happy to simplify things.

To solve this problem, I created a `spec['python'].home` attribute that works the same way as `spec['python'].prefix` but queries Python to figure out where it was actually installed. @tgamblin Is there any way to overwrite `spec['python'].prefix`? I think it's currently immutable.

## Command

In general, Python 2 comes with both `python` and `python2` commands, while Python 3 only comes with a `python3` command. But this is up to the OS developers. For example, `/usr/bin/python` on Gentoo is actually Python 3. Worse yet, if someone is using an externally installed Python, all 3 commands may exist in the same directory! Here's what I'm thinking:

If the spec is for Python 3, try searching for the `python3` command.
If the spec is for Python 2, try searching for the `python2` command.
If neither are found, try searching for the `python` command.

## Libraries

Spack installs Python libraries in `spec['python'].prefix.lib`. Except on openSUSE 13, where it installs to `spec['python'].prefix.lib64` (see spack#2295 and spack#2253). On my CentOS 6 machine, the Python libraries are installed in `/usr/lib64`. Both need to work.

The libraries themselves change name depending on OS and Python version. For Python 2.7 on macOS, I'm seeing:
```
lib/libpython2.7.dylib
```
For Python 3.6 on CentOS 6, I'm seeing:
```
lib/libpython3.so
lib/libpython3.6m.so.1.0
lib/libpython3.6m.so -> lib/libpython3.6m.so.1.0
```
Notice the `m` after the version number. Yeah, that's a thing.

## Headers

In Python 2.7, I'm seeing:
```
include/python2.7/pyconfig.h
```
In Python 3.6, I'm seeing:
```
include/python3.6m/pyconfig.h
```
It looks like all Python 3 installations have this `m`. Tested with Python 3.2 and 3.6 on macOS and CentOS 6

Spack has really nice support for libraries (`find_libraries` and `LibraryList`), but nothing for headers. Fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants