当前位置: 首页>>代码示例>>Python>>正文


Python site.getusersitepackages方法代码示例

本文整理汇总了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 
开发者ID:Pylons,项目名称:hupper,代码行数:26,代码来源:compat.py

示例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 
开发者ID:plasticityai,项目名称:magnitude,代码行数:22,代码来源:setup.py

示例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 
开发者ID:googlecolab,项目名称:colabtools,代码行数:18,代码来源:_pip.py

示例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 
开发者ID:softbankrobotics-research,项目名称:qibullet,代码行数:24,代码来源:setup.py

示例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 
开发者ID:thonny,项目名称:thonny,代码行数:20,代码来源:common.py

示例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(),
        ) 
开发者ID:thonny,项目名称:thonny,代码行数:21,代码来源:backend.py

示例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()] 
开发者ID:src-d,项目名称:modelforge,代码行数:8,代码来源:environment.py

示例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 
开发者ID:encarsia,项目名称:gpt,代码行数:10,代码来源:setup.py

示例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()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_site.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:42,代码来源:test_site.py

示例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 
开发者ID:spyder-ide,项目名称:spyder-kernels,代码行数:35,代码来源:utils.py

示例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) 
开发者ID:giampaolo,项目名称:psutil,代码行数:11,代码来源:purge_installation.py

示例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') 
开发者ID:Deepwalker,项目名称:pundler,代码行数:33,代码来源:pundle.py

示例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) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:10,代码来源:test_site.py

示例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,)) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:31,代码来源:conftest.py


注:本文中的site.getusersitepackages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。