summaryrefslogtreecommitdiff
path: root/var
diff options
context:
space:
mode:
authorBarry Smith <bsmith@mcs.anl.gov>2016-10-30 19:13:16 -0500
committerTodd Gamblin <tgamblin@llnl.gov>2016-10-30 17:13:16 -0700
commita714377123cf2aefb895badfbf9d4baf81b39654 (patch)
tree91c9b55d3667b841c39c20a08c93ba637f545983 /var
parent9989f8e2675495763d35b26ccc9fcc07db7fd50f (diff)
downloadspack-a714377123cf2aefb895badfbf9d4baf81b39654.tar.gz
spack-a714377123cf2aefb895badfbf9d4baf81b39654.tar.bz2
spack-a714377123cf2aefb895badfbf9d4baf81b39654.tar.xz
spack-a714377123cf2aefb895badfbf9d4baf81b39654.zip
python: PYTHONHOME may not be the same as the prefix of the python executable (#2173)
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
Diffstat (limited to 'var')
-rw-r--r--var/spack/repos/builtin/packages/python/package.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py
index f3380cf75d..7fe2cab897 100644
--- a/var/spack/repos/builtin/packages/python/package.py
+++ b/var/spack/repos/builtin/packages/python/package.py
@@ -202,8 +202,27 @@ class Python(Package):
def setup_dependent_environment(self, spack_env, run_env, extension_spec):
"""Set PYTHONPATH to include site-packages dir for the
extension and any other python extensions it depends on."""
- pythonhome = self.prefix
- spack_env.set('PYTHONHOME', pythonhome)
+ # The python executable for version 3 may be python3 or python
+ # See https://github.com/LLNL/spack/pull/2173#issuecomment-257170199
+ pythonex = 'python{0}'.format('3' if self.spec.satisfies('@3') else '')
+ if os.path.isdir(self.prefix.bin):
+ base = self.prefix.bin
+ else:
+ base = self.prefix
+ if not os.path.isfile(os.path.join(base, pythonex)):
+ if self.spec.satisfies('@3'):
+ python = Executable(os.path.join(base, 'python'))
+ version = python('-c', 'import sys; print(sys.version)',
+ output=str)
+ if version.startswith('3'):
+ pythonex = 'python'
+ else:
+ raise RuntimeError('Cannot locate python executable')
+ else:
+ raise RuntimeError('Cannot locate python executable')
+ python = Executable(os.path.join(base, pythonex))
+ prefix = python('-c', 'import sys; print(sys.prefix)', output=str)
+ spack_env.set('PYTHONHOME', prefix.strip('\n'))
python_paths = []
for d in extension_spec.traverse(deptype=nolink, deptype_query='run'):