當前位置: 首頁>>代碼示例>>Python>>正文


Python site.getsitepackages方法代碼示例

本文整理匯總了Python中site.getsitepackages方法的典型用法代碼示例。如果您正苦於以下問題:Python site.getsitepackages方法的具體用法?Python site.getsitepackages怎麽用?Python site.getsitepackages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在site的用法示例。


在下文中一共展示了site.getsitepackages方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_getsitepackages

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def test_getsitepackages(self):
        site.PREFIXES = ['xoxo']
        dirs = site.getsitepackages()

        if sys.platform in ('os2emx', 'riscos'):
            self.assertEqual(len(dirs), 1)
            wanted = os.path.join('xoxo', 'Lib', 'site-packages')
            self.assertEqual(dirs[0], wanted)
        elif os.sep == '/':
            # OS X, Linux, FreeBSD, etc
            self.assertEqual(len(dirs), 2)
            wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
                                  'site-packages')
            self.assertEqual(dirs[0], wanted)
            wanted = os.path.join('xoxo', 'lib', 'site-python')
            self.assertEqual(dirs[1], wanted)
        else:
            # other platforms
            self.assertEqual(len(dirs), 2)
            self.assertEqual(dirs[0], 'xoxo')
            wanted = os.path.join('xoxo', 'lib', 'site-packages')
            self.assertEqual(dirs[1], wanted) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,代碼來源:test_site.py

示例2: install

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def install(setup_py, prefix, lib_dir, bin_dir):
    __file__ = setup_py

    with getattr(tokenize, "open", open)(setup_py) as f:
        code = f.read().replace("\\r\\n", "\n")
    if os.path.exists(os.path.join(lib_dir, "site.py")):
        # Remove the custom site.py for editable install.
        # It will be added back after installation is done.
        os.remove(os.path.join(lib_dir, "site.py"))
    sys.argv[1:] = [
        "develop",
        "--install-dir={0}".format(lib_dir),
        "--no-deps",
        "--prefix={0}".format(prefix),
        "--script-dir={0}".format(bin_dir),
        "--site-dirs={0}".format(lib_dir),
    ]
    if os.path.normpath(lib_dir) not in site.getsitepackages():
        # Patches the script writer to inject library path
        easy_install.ScriptWriter.template = easy_install.ScriptWriter.template.replace(
            "import sys",
            "import sys\nsys.path.insert(0, {0!r})".format(lib_dir.replace("\\", "/")),
        )
    exec(compile(code, __file__, "exec")) 
開發者ID:frostming,項目名稱:pdm,代碼行數:26,代碼來源:_editable_install.py

示例3: wmi

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def wmi():
    try:
        # PyMI depends on the MI API, not available by default on systems older
        # than Windows 8 / Windows Server 2012
        import wmi
        return wmi
    except ImportError:
        LOG.debug("Couldn't load PyMI module, using legacy WMI")

        wmi_path = None
        for packages_path in site.getsitepackages():
            path = os.path.join(packages_path, "wmi.py")
            if os.path.isfile(path):
                wmi_path = path
                break
        if wmi_path is None:
            raise exception.ItemNotFoundException("wmi module not found")

        return imp.load_source("wmi", wmi_path) 
開發者ID:cloudbase,項目名稱:cloudbase-init,代碼行數:21,代碼來源:wmi_loader.py

示例4: get_site_packages

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def get_site_packages():
    """
    This is a hack to work around site.getsitepackages() not working in
    virtualenv. See https://github.com/pypa/virtualenv/issues/355
    """
    # Another hack...
    # Relies on the fact that os.py is in the dir above site_packages
    os_location = os.path.dirname(os.__file__)
    site_packages = []
    # Consider Debain/Ubuntu custom
    for site in ["site-packages", "dist-packages"]:
        site_path = os.path.join(os_location, site)
        if os.path.isdir(site_path):
            site_packages.append(site_path)
    try:
        site_packages += _site.getsitepackages()
    except AttributeError, ex:
        print("WARNING: Error trying to call site.getsitepackages(). Exception: %r" % ex)
        print("         Do you have sufficient permissions?") 
        print("         Otherwise this could probably be virtualenv issue#355") 
開發者ID:tintinweb,項目名稱:scapy-ssl_tls,代碼行數:22,代碼來源:setup.py

示例5: get_site_packages

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def get_site_packages():  # pragma: no cover
    try:
        paths = site.getsitepackages()
        if site.ENABLE_USER_SITE:
            paths.append(site.getusersitepackages())
        return paths

    # virtualenv does not ship with a getsitepackages impl so we fallback
    # to using distutils if we can
    # https://github.com/pypa/virtualenv/issues/355
    except Exception:
        try:
            from distutils.sysconfig import get_python_lib

            return [get_python_lib()]

        # just incase, don't fail here, it's not worth it
        except Exception:
            return []


################################################
# cross-compatible metaclass implementation
# Copyright (c) 2010-2012 Benjamin Peterson 
開發者ID:Pylons,項目名稱:hupper,代碼行數:26,代碼來源:compat.py

示例6: clean_mod

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def clean_mod():
    r"""
    清除已產生的 site-packages\comtypes\gen\*.py
    """
    pkgdirs = site.getsitepackages()
    for pkgdir in pkgdirs:
        if not pkgdir.endswith('site-packages'):
            continue

        gendir = pkgdir + r'\comtypes\gen'
        if not os.path.isdir(gendir):
            continue

        logger = logging.getLogger('helper')
        logger.info('  路徑 %s', gendir)

        for item in os.listdir(gendir):
            if item.endswith('.py'):
                logger.info('  移除 %s', item)
                os.remove(gendir + '\\' + item)

        cache_dir = gendir + '\\' + '__pycache__'
        if os.path.isdir(cache_dir):
            logger.info('  移除 __pycache__')
            shutil.rmtree(cache_dir) 
開發者ID:tacosync,項目名稱:skcom,代碼行數:27,代碼來源:helper.py

示例7: _extract_toplevel_packages

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def _extract_toplevel_packages(pip_output):
  """Extract the list of toplevel packages associated with a pip install."""
  # Account for default installations and --user installations (most common).
  # Note: we should possibly also account for --root, --prefix, & -t/--target.
  sitepackages = site.getsitepackages() + [site.getusersitepackages()]
  for package in _extract_installed_packages(pip_output):
    infodir = _get_distinfo_path(package, sitepackages)
    if not infodir:
      continue
    toplevel = os.path.join(infodir, "top_level.txt")
    if not os.path.exists(toplevel):
      continue
    for line in open(toplevel):
      line = line.strip()
      if line:
        yield line 
開發者ID:googlecolab,項目名稱:colabtools,代碼行數:18,代碼來源:_pip.py

示例8: get_install_directory

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def get_install_directory():
    """
    Return the installation directory, or None
    """
    if '--user' in sys.argv:
        paths = site.getusersitepackages()
    else:
        paths = site.getsitepackages()

    if isinstance(paths, str):
        paths = [paths]

    for path in paths:
        if platform.system() == "Windows":
            path += "\\qibullet"
        else:
            path += "/qibullet"

        if os.path.exists(path):
            return path

    return None 
開發者ID:softbankrobotics-research,項目名稱:qibullet,代碼行數:24,代碼來源:setup.py

示例9: generate_poses

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def generate_poses(object_folder, output_folder, renders_per_product, blender_attributes):
    "Make a call to Blender to generate poses"
    # python_sites = site.getsitepackages()[0]
    # python_sites = '/vol/project/2017/530/g1753002/ocadovenv/ocadovenv/lib/python3.5/site-packages'

    blender_path = '/vol/project/2017/530/g1753002/Blender/blender-2.79-linux-glibc219-x86_64/blender'
    blender_script_path = os.path.join(src_dir, 'rendering', 'render_poses.py')
    config_file_path = os.path.join(src_dir, 'rendering', 'config.json')

    blender_args = [blender_path, '--background', '--python', blender_script_path, '--',
                    src_dir,
                    # config_file_path,
                    object_folder,
                    output_folder,
                    str(renders_per_product),
                    json.dumps(blender_attributes)]

    # blender_args = [blender_path, '--background', '--python']

    print('Rendering...')
    subprocess.check_call(blender_args)
    print('Rendering done!') 
開發者ID:921kiyo,項目名稱:3d-dl,代碼行數:24,代碼來源:render_example.py

示例10: __init__

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def __init__(self):
        """Initialize a new DistFilesFinder."""
        try:
            self.sitedirs = set(site.getsitepackages() + [site.getusersitepackages()])
        except AttributeError:
            self.sitedirs = [get_python_lib()] 
開發者ID:src-d,項目名稱:modelforge,代碼行數:8,代碼來源:environment.py

示例11: _find_install_path

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def _find_install_path():
    if "--user" in sys.argv:
        inst = site.getusersitepackages()
        prefix = site.getuserbase()
    else:
        inst = site.getsitepackages()[0]
        prefix = sys.prefix
    return inst, prefix 
開發者ID:encarsia,項目名稱:gpt,代碼行數:10,代碼來源:setup.py

示例12: pytorch_import_fix

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def pytorch_import_fix() -> None:
    """Hackfix needed before pytorch import ("dlopen: cannot load any more object with static TLS")
    See issue #305
    """
    try:
        for packages in site.getsitepackages():
            for lib in glob.glob(f'{packages}/torch/lib/libgomp*.so*'):
                ctypes.cdll.LoadLibrary(lib)
    except Exception:  # pylint: disable=broad-except
        pass 
開發者ID:facebookresearch,項目名稱:nevergrad,代碼行數:12,代碼來源:tools.py

示例13: run_cstm_cmd

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def run_cstm_cmd(self):
    # append binary folder to PYTHON PATH
    if self.tools:
        with open(os.path.join(site.getsitepackages()[0], 'nanopype.pth'), 'w') as fp:
            print('import os; os.environ["PATH"] = "{dir}" + os.pathsep + os.environ["PATH"]'.format(dir=os.path.abspath(self.tools)), file=fp) 
開發者ID:giesselmann,項目名稱:nanopype,代碼行數:7,代碼來源:setup.py

示例14: main

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def main():
    locations = [site.getusersitepackages()]
    locations += site.getsitepackages()
    for root in locations:
        if os.path.isdir(root):
            for name in os.listdir(root):
                if PKGNAME in name:
                    abspath = os.path.join(root, name)
                    rmpath(abspath) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:11,代碼來源:purge_installation.py

示例15: test_getsitepackages

# 需要導入模塊: import site [as 別名]
# 或者: from site import getsitepackages [as 別名]
def test_getsitepackages(self):
        site.PREFIXES = ['xoxo']
        dirs = site.getsitepackages()

        if sys.platform in ('os2emx', 'riscos'):
            self.assertEqual(len(dirs), 1)
            wanted = os.path.join('xoxo', 'Lib', 'site-packages')
            self.assertEqual(dirs[0], wanted)
        elif (sys.platform == "darwin" and
            sysconfig.get_config_var("PYTHONFRAMEWORK")):
            # OS X framework builds
            site.PREFIXES = ['Python.framework']
            dirs = site.getsitepackages()
            self.assertEqual(len(dirs), 3)
            wanted = os.path.join('/Library',
                                  sysconfig.get_config_var("PYTHONFRAMEWORK"),
                                  sys.version[:3],
                                  'site-packages')
            self.assertEqual(dirs[2], wanted)
        elif os.sep == '/':
            # OS X non-framwework builds, Linux, FreeBSD, etc
            self.assertEqual(len(dirs), 2)
            wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
                                  'site-packages')
            self.assertEqual(dirs[0], wanted)
            wanted = os.path.join('xoxo', 'lib', 'site-python')
            self.assertEqual(dirs[1], wanted)
        else:
            # other platforms
            self.assertEqual(len(dirs), 2)
            self.assertEqual(dirs[0], 'xoxo')
            wanted = os.path.join('xoxo', 'lib', 'site-packages')
            self.assertEqual(dirs[1], wanted) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:35,代碼來源:test_site.py


注:本文中的site.getsitepackages方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。