當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。