get_python_lib.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 # ============================================================================
4 # Copyright (c) 2011-2012 University of Pennsylvania
5 # Copyright (c) 2013-2016 Andreas Schuh
6 # All rights reserved.
7 #
8 # See COPYING file for license information or visit
9 # https://cmake-basis.github.io/download.html#license
10 # ============================================================================
11 
12 ##############################################################################
13 # @file get_python_lib.py
14 # @brief Auxiliary Python script to get installation directory for site packages.
15 ##############################################################################
16 
17 from __future__ import absolute_import, print_function, unicode_literals
18 
19 try:
20  # this uses the same as packages which use easy_install for the installation
21  # and returns also the proper site-packages directory on Ubuntu
22  from setuptools.command.easy_install import easy_install
23 
24  class easy_install_default(easy_install):
25  def __init__(self):
26  from distutils.dist import Distribution
27  dist = Distribution()
28  self.distribution = dist
29  self.initialize_options()
30  self._dry_run = None
31  self.verbose = dist.verbose
32  self.force = None
33  self.help = 0
34  self.finalized = 0
35 
37  import distutils.errors
38  try:
39  e.finalize_options()
40  except distutils.errors.DistutilsError:
41  pass
42 
43  print(e.install_dir.rstrip('/\\'))
44 except:
45  # however, if the setuptools are not installed, fall back to the distutils
46  import distutils.sysconfig
47  print(distutils.sysconfig.get_python_lib().rstrip('/\\'))