本文整理匯總了Python中site.getusersitepackages方法的典型用法代碼示例。如果您正苦於以下問題:Python site.getusersitepackages方法的具體用法?Python site.getusersitepackages怎麽用?Python site.getusersitepackages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類site
的用法示例。
在下文中一共展示了site.getusersitepackages方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_site_packages
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [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
示例2: install_wheel
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [as 別名]
def install_wheel(whl):
"""Installs a wheel file"""
whl_args = [
sys.executable,
'-m',
'pip',
'install',
'--ignore-installed',
]
rc = subprocess.Popen(whl_args + [whl]).wait()
if rc != 0:
try:
import site
if hasattr(site, 'getusersitepackages'):
site_packages = site.getusersitepackages()
print("Installing to user site packages...", site_packages)
rc = subprocess.Popen(whl_args + ["--user"] + [whl]).wait()
except ImportError:
pass
return rc
示例3: _extract_toplevel_packages
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [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
示例4: get_install_directory
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [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
示例5: get_exe_dirs
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [as 別名]
def get_exe_dirs():
result = []
if site.ENABLE_USER_SITE:
if platform.system() == "Windows":
if site.getusersitepackages():
result.append(site.getusersitepackages().replace("site-packages", "Scripts"))
else:
if site.getuserbase():
result.append(site.getuserbase() + "/bin")
main_scripts = os.path.join(sys.prefix, "Scripts")
if os.path.isdir(main_scripts) and main_scripts not in result:
result.append(main_scripts)
if os.path.dirname(sys.executable) not in result:
result.append(os.path.dirname(sys.executable))
return result
示例6: _cmd_get_environment_info
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [as 別名]
def _cmd_get_environment_info(self, cmd):
return ToplevelResponse(
main_dir=self._main_dir,
path=sys.path,
usersitepackages=site.getusersitepackages() if site.ENABLE_USER_SITE else None,
prefix=sys.prefix,
welcome_text="Python " + _get_python_version_string(),
executable=sys.executable,
exe_dirs=get_exe_dirs(),
in_venv=(
hasattr(sys, "base_prefix")
and sys.base_prefix != sys.prefix
or hasattr(sys, "real_prefix")
and getattr(sys, "real_prefix") != sys.prefix
),
python_version=_get_python_version_string(),
cwd=os.getcwd(),
)
示例7: __init__
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [as 別名]
def __init__(self):
"""Initialize a new DistFilesFinder."""
try:
self.sitedirs = set(site.getsitepackages() + [site.getusersitepackages()])
except AttributeError:
self.sitedirs = [get_python_lib()]
示例8: _find_install_path
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [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
示例9: test_getusersitepackages
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [as 別名]
def test_getusersitepackages(self):
site.USER_SITE = None
site.USER_BASE = None
user_site = site.getusersitepackages()
# the call sets USER_BASE *and* USER_SITE
self.assertEqual(site.USER_SITE, user_site)
self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
self.assertEqual(site.USER_BASE, site.getuserbase())
示例10: test_no_home_directory
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [as 別名]
def test_no_home_directory(self):
# bpo-10496: getuserbase() and getusersitepackages() must not fail if
# the current user has no home directory (if expanduser() returns the
# path unchanged).
site.USER_SITE = None
site.USER_BASE = None
sysconfig._CONFIG_VARS = None
with EnvironmentVarGuard() as environ, \
support.swap_attr(os.path, 'expanduser', lambda path: path):
del environ['PYTHONUSERBASE']
del environ['APPDATA']
user_base = site.getuserbase()
self.assertTrue(user_base.startswith('~' + os.sep),
user_base)
user_site = site.getusersitepackages()
self.assertTrue(user_site.startswith(user_base), user_site)
def fake_isdir(path):
fake_isdir.arg = path
return False
fake_isdir.arg = None
def must_not_be_called(*args):
raise AssertionError
with support.swap_attr(os.path, 'isdir', fake_isdir), \
support.swap_attr(site, 'addsitedir', must_not_be_called), \
support.swap_attr(site, 'ENABLE_USER_SITE', True):
# addusersitepackages() must not add user_site to sys.path
# if it is not an existing directory
known_paths = set()
site.addusersitepackages(known_paths)
self.assertEqual(fake_isdir.arg, user_site)
self.assertFalse(known_paths)
示例11: create_pathlist
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [as 別名]
def create_pathlist():
"""
Create list of Python library paths to be skipped from module
reloading and Pdb steps.
"""
# Get standard installation paths
try:
paths = sysconfig.get_paths()
standard_paths = [paths['stdlib'],
paths['purelib'],
paths['scripts'],
paths['data']]
except Exception:
standard_paths = []
# Get user installation path
# See spyder-ide/spyder#8776
try:
import site
if getattr(site, 'getusersitepackages', False):
# Virtualenvs don't have this function but
# conda envs do
user_path = [site.getusersitepackages()]
elif getattr(site, 'USER_SITE', False):
# However, it seems virtualenvs have this
# constant
user_path = [site.USER_SITE]
else:
user_path = []
except Exception:
user_path = []
return standard_paths + user_path
示例12: main
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [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)
示例13: fixate
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [as 別名]
def fixate():
"puts activation code to usercustomize.py for user"
print_message('Fixate')
import site
userdir = site.getusersitepackages()
if not userdir:
raise PundleException('Can`t fixate due user have not site package directory')
try:
makedirs(userdir)
except OSError:
pass
template = FIXATE_TEMPLATE.replace('op.dirname(__file__)', "'%s'" % op.abspath(op.dirname(__file__)))
usercustomize_file = op.join(userdir, 'usercustomize.py')
print_message('Will edit %s file' % usercustomize_file)
if op.exists(usercustomize_file):
content = open(usercustomize_file).read()
if '# pundle user customization start' in content:
regex = re.compile(r'\n# pundle user customization start.*# pundle user customization end\n', re.DOTALL)
content, res = regex.subn(template, content)
open(usercustomize_file, 'w').write(content)
else:
open(usercustomize_file, 'a').write(content)
else:
open(usercustomize_file, 'w').write(template)
link_file = op.join(userdir, 'pundle.py')
if op.lexists(link_file):
print_message('Remove exist link to pundle')
os.unlink(link_file)
print_message('Create link to pundle %s' % link_file)
os.symlink(op.abspath(__file__), link_file)
print_message('Complete')
示例14: test_getusersitepackages
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [as 別名]
def test_getusersitepackages(self):
site.USER_SITE = None
site.USER_BASE = None
user_site = site.getusersitepackages()
# the call sets USER_BASE *and* USER_SITE
self.assertEqual(site.USER_SITE, user_site)
self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
示例15: pytest_report_header
# 需要導入模塊: import site [as 別名]
# 或者: from site import getusersitepackages [as 別名]
def pytest_report_header(config):
print('PYDEVD_USE_CYTHON: %s' % (TEST_CYTHON,))
print('PYDEVD_TEST_VM: %s' % (PYDEVD_TEST_VM,))
try:
import multiprocessing
except ImportError:
pass
else:
print('Number of processors: %s' % (multiprocessing.cpu_count(),))
print('Relevant system paths:')
print('sys.executable: %s' % (sys.executable,))
print('sys.prefix: %s' % (sys.prefix,))
if hasattr(sys, 'base_prefix'):
print('sys.base_prefix: %s' % (sys.base_prefix,))
if hasattr(sys, 'real_prefix'):
print('sys.real_prefix: %s' % (sys.real_prefix,))
if hasattr(site, 'getusersitepackages'):
print('site.getusersitepackages(): %s' % (site.getusersitepackages(),))
if hasattr(site, 'getsitepackages'):
print('site.getsitepackages(): %s' % (site.getsitepackages(),))
for path in sys.path:
if os.path.exists(path) and os.path.basename(path) == 'site-packages':
print('Folder with "site-packages" in sys.path: %s' % (path,))