本文整理汇总了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)
示例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"))
示例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)
示例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")
示例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
示例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)
示例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
示例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
示例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!')
示例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()]
示例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
示例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
示例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)
示例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)
示例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)