Python site.getusersitepackages() Examples
The following are 30
code examples of site.getusersitepackages().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
site
, or try the search function
.
Example #1
Source File: compat.py From hupper with MIT License | 7 votes |
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
Example #2
Source File: _pip.py From colabtools with Apache License 2.0 | 6 votes |
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
Example #3
Source File: setup.py From magnitude with MIT License | 6 votes |
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
Example #4
Source File: backend.py From thonny with MIT License | 6 votes |
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(), )
Example #5
Source File: common.py From thonny with MIT License | 6 votes |
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
Example #6
Source File: setup.py From qibullet with Apache License 2.0 | 6 votes |
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
Example #7
Source File: setup.py From supersqlite with MIT License | 6 votes |
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
Example #8
Source File: __main__.py From PrettyErrors with MIT License | 5 votes |
def getusersitepackages(): return [site.getusersitepackages()]
Example #9
Source File: cheat.py From collection with MIT License | 5 votes |
def search_cheat (self): available = [] import site site_system = site.getsitepackages() site_user = site.getusersitepackages() for name in [site_user] + site_system: path = os.path.join(name, 'cheat') if not os.path.exists(path): continue path = os.path.join(path, 'cheatsheets') if not os.path.exists(path): continue available.append(path) return available
Example #10
Source File: package_utils.py From nni with MIT License | 5 votes |
def get_nni_installation_parent_dir(): ''' Find nni installation parent directory ''' def try_installation_path_sequentially(*sitepackages): '''Try different installation path sequentially util nni is found. Return None if nothing is found ''' def _generate_installation_path(sitepackages_path): python_dir = get_python_dir(sitepackages_path) entry_file = os.path.join(python_dir, 'nni', 'main.js') if os.path.isfile(entry_file): return python_dir return None for sitepackage in sitepackages: python_dir = _generate_installation_path(sitepackage) if python_dir: return python_dir return None if os.getenv('VIRTUAL_ENV'): # if 'virtualenv' package is used, `site` has not attr getsitepackages, so we will instead use VIRTUAL_ENV # Note that conda venv will not have VIRTUAL_ENV python_dir = os.getenv('VIRTUAL_ENV') else: python_sitepackage = site.getsitepackages()[0] # If system-wide python is used, we will give priority to using `local sitepackage`--"usersitepackages()" given # that nni exists there if python_sitepackage.startswith('/usr') or python_sitepackage.startswith('/Library'): python_dir = try_installation_path_sequentially(site.getusersitepackages(), site.getsitepackages()[0]) else: python_dir = try_installation_path_sequentially(site.getsitepackages()[0], site.getusersitepackages()) return python_dir
Example #11
Source File: test_site.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #12
Source File: vsrepo.py From vsrepo with MIT License | 5 votes |
def get_vs_installation_site(): if is_venv(): try: return os.path.dirname(detect_vapoursynth_installation()) except ImportError: import setuptools return os.path.dirname(os.path.dirname(setuptools.__file__)) import site return site.getusersitepackages()
Example #13
Source File: setup.py From supersqlite with MIT License | 5 votes |
def get_site_packages(): """ Gets all site_packages paths """ try: import site if hasattr(site, 'getsitepackages'): site_packages = site.getsitepackages() else: from distutils.sysconfig import get_python_lib site_packages = [get_python_lib()] if hasattr(site, 'getusersitepackages'): site_packages = site_packages + [site.getusersitepackages()] return site_packages except BaseException: return []
Example #14
Source File: test_site.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #15
Source File: __main__.py From PrettyErrors with MIT License | 5 votes |
def getusersitepackages(): return []
Example #16
Source File: listing.py From import-order with GNU General Public License v3.0 | 5 votes |
def list_site_packages_paths(): site_packages_paths = set([site.USER_SITE]) try: site_packages_paths.update(site.getsitepackages()) except AttributeError: pass try: user_site = site.getusersitepackages() if isinstance(user_site, str): site_packages_paths.add(user_site) else: site_packages_paths.update(user_site) except AttributeError: pass try: virtualenv_path = os.environ['VIRTUAL_ENV'] except KeyError: pass else: virtualenv_src_path = os.path.join(virtualenv_path, 'src') site_packages_paths.update( path for path in sys.path if path.startswith(virtualenv_path) and ( 'site-packages' in path or path.startswith(virtualenv_src_path) ) ) return site_packages_paths
Example #17
Source File: __main__.py From PrettyErrors with MIT License | 5 votes |
def getallsitepackages(): return getsitepackages() + getusersitepackages()
Example #18
Source File: backend.py From thonny with MIT License | 5 votes |
def _cmd_get_active_distributions(self, cmd): try: # if it is called after first installation to user site packages # this dir is not yet in sys.path if ( site.ENABLE_USER_SITE and site.getusersitepackages() and os.path.exists(site.getusersitepackages()) and site.getusersitepackages() not in sys.path ): # insert before first site packages item for i, item in enumerate(sys.path): if "site-packages" in item or "dist-packages" in item: sys.path.insert(i, site.getusersitepackages()) break else: sys.path.append(site.getusersitepackages()) import pkg_resources pkg_resources._initialize_master_working_set() dists = { dist.key: { "project_name": dist.project_name, "key": dist.key, "location": dist.location, "version": dist.version, } for dist in pkg_resources.working_set } # pylint: disable=not-an-iterable return InlineResponse( "get_active_distributions", distributions=dists, usersitepackages=site.getusersitepackages() if site.ENABLE_USER_SITE else None, ) except Exception: return InlineResponse("get_active_distributions", error=traceback.format_exc())
Example #19
Source File: backend.py From thonny with MIT License | 5 votes |
def _is_interesting_module_file(self, path): # interesting files are the files in the same directory as main module # or the ones with breakpoints # When command is "resume", then only modules with breakpoints are interesting # (used to be more flexible, but this caused problems # when main script was in ~/. Then user site library became interesting as well) result = self._file_interest_cache.get(path, None) if result is not None: return result _, extension = os.path.splitext(path.lower()) result = ( self._get_breakpoints_in_file(path) or self._main_module_path is not None and is_same_path(path, self._main_module_path) or extension in (".py", ".pyw") and ( self._current_command.get("allow_stepping_into_libraries", False) or ( path_startswith(path, os.path.dirname(self._main_module_path)) # main module may be at the root of the fs and not path_startswith(path, sys.prefix) and not path_startswith(path, sys.base_prefix) and not path_startswith(path, site.getusersitepackages() or "usersitenotexists") ) ) and not path_startswith(path, self._thonny_src_dir) ) self._file_interest_cache[path] = result return result
Example #20
Source File: backend.py From thonny with MIT License | 5 votes |
def _is_library_file(filename): return ( filename is None or path_startswith(filename, sys.prefix) or hasattr(sys, "base_prefix") and path_startswith(filename, sys.base_prefix) or hasattr(sys, "real_prefix") and path_startswith(filename, getattr(sys, "real_prefix")) or site.ENABLE_USER_SITE and path_startswith(filename, site.getusersitepackages()) )
Example #21
Source File: fishnet.py From fishnet with GNU General Public License v3.0 | 5 votes |
def is_user_site_package(): try: user_site = site.getusersitepackages() except AttributeError: return False return os.path.abspath(__file__).startswith(os.path.join(user_site, ""))
Example #22
Source File: test_site.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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)
Example #23
Source File: purge_installation.py From pyftpdlib with MIT License | 5 votes |
def main(): locations = [site.getusersitepackages()] locations.extend(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)
Example #24
Source File: test_site.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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)
Example #25
Source File: conftest.py From PyDev.Debugger with Eclipse Public License 1.0 | 5 votes |
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,))
Example #26
Source File: environment.py From modelforge with Apache License 2.0 | 5 votes |
def __init__(self): """Initialize a new DistFilesFinder.""" try: self.sitedirs = set(site.getsitepackages() + [site.getusersitepackages()]) except AttributeError: self.sitedirs = [get_python_lib()]
Example #27
Source File: setup.py From gpt with GNU General Public License v3.0 | 5 votes |
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
Example #28
Source File: test_site.py From ironpython2 with Apache License 2.0 | 5 votes |
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())
Example #29
Source File: test_site.py From ironpython2 with Apache License 2.0 | 5 votes |
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)
Example #30
Source File: utils.py From spyder-kernels with MIT License | 5 votes |
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