本文整理汇总了Python中sys.real_prefix方法的典型用法代码示例。如果您正苦于以下问题:Python sys.real_prefix方法的具体用法?Python sys.real_prefix怎么用?Python sys.real_prefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.real_prefix方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _find_config_dir
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def _find_config_dir(self, config_dir):
# Look for config in the virtual environment
# virtualenv puts the original prefix in sys.real_prefix
# pyenv puts it in sys.base_prefix
venv_d = os.path.join(sys.prefix, 'etc/a10')
has_prefix = (hasattr(sys, 'real_prefix') or hasattr(sys, 'base_prefix'))
env_override = os.environ.get('A10_CONFIG_DIR', None)
if config_dir is not None:
d = config_dir
elif env_override is not None:
d = env_override
elif has_prefix and os.path.exists(venv_d):
d = venv_d
elif os.path.exists('/etc/neutron/services/loadbalancer/a10networks'):
d = '/etc/neutron/services/loadbalancer/a10networks'
else:
d = '/etc/a10'
return d
示例2: pydeps2reqs
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def pydeps2reqs(deps):
"""Convert a deps instance into requirements.
"""
reqs = defaultdict(set)
for k, v in list(deps.items()):
# not a built-in
p = v['path']
if p and not p.startswith(sys.real_prefix):
if p.startswith(sys.prefix) and 'site-packages' in p:
if not p.endswith('.pyd'):
if '/win32/' in p.replace('\\', '/'):
reqs['win32'] |= set(v['imported_by'])
else:
name = k.split('.', 1)[0]
if name not in skiplist:
reqs[name] |= set(v['imported_by'])
if '_dummy' in reqs:
del reqs['_dummy']
return '\n'.join(dep2req(name, reqs[name]) for name in sorted(reqs))
示例3: run
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def run(self, *args, **kwargs):
func = kwargs.pop("func", Argv.get_output)
kwargs.setdefault("stdin", DEVNULL)
kwargs['env'] = deepcopy(os.environ)
if 'VIRTUAL_ENV' in kwargs['env'] or 'CONDA_PREFIX' in kwargs['env']:
kwargs['env'].pop('VIRTUAL_ENV', None)
kwargs['env'].pop('CONDA_PREFIX', None)
kwargs['env'].pop('PYTHONPATH', None)
if hasattr(sys, "real_prefix") and hasattr(sys, "base_prefix"):
path = ':'+kwargs['env']['PATH']
path = path.replace(':'+sys.base_prefix, ':'+sys.real_prefix, 1)
kwargs['env']['PATH'] = path
if check_if_command_exists("poetry"):
argv = Argv("poetry", *args)
else:
argv = Argv(self._python, "-m", "poetry", *args)
self.log.debug("running: %s", argv)
return func(argv, **kwargs)
示例4: setup_detect_python2
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def setup_detect_python2():
"""
Call this before using the refactoring tools to create them on demand
if needed.
"""
if None in [RTs._rt_py2_detect, RTs._rtp_py2_detect]:
RTs._rt_py2_detect = RefactoringTool(py2_detect_fixers)
RTs._rtp_py2_detect = RefactoringTool(py2_detect_fixers,
{'print_function': True})
# We need to find a prefix for the standard library, as we don't want to
# process any files there (they will already be Python 3).
#
# The following method is used by Sanjay Vinip in uprefix. This fails for
# ``conda`` environments:
# # In a non-pythonv virtualenv, sys.real_prefix points to the installed Python.
# # In a pythonv venv, sys.base_prefix points to the installed Python.
# # Outside a virtual environment, sys.prefix points to the installed Python.
# if hasattr(sys, 'real_prefix'):
# _syslibprefix = sys.real_prefix
# else:
# _syslibprefix = getattr(sys, 'base_prefix', sys.prefix)
# Instead, we use the portion of the path common to both the stdlib modules
# ``math`` and ``urllib``.
示例5: find_python_dll
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def find_python_dll():
# We can't do much here:
# - find it in the virtualenv (sys.prefix)
# - find it in python main dir (sys.base_prefix, if in a virtualenv)
# - sys.real_prefix is main dir for virtualenvs in Python 2.7
# - in system32,
# - ortherwise (Sxs), I don't know how to get it.
stems = [sys.prefix]
if hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix:
stems.append(sys.base_prefix)
elif hasattr(sys, 'real_prefix') and sys.real_prefix != sys.prefix:
stems.append(sys.real_prefix)
sub_dirs = ['', 'lib', 'bin']
# generate possible combinations of directory trees and sub-directories
lib_dirs = []
for stem in stems:
for folder in sub_dirs:
lib_dirs.append(os.path.join(stem, folder))
# add system directory as well
if 'SYSTEMROOT' in os.environ:
lib_dirs.append(os.path.join(os.environ['SYSTEMROOT'], 'System32'))
# search in the file system for possible candidates
major_version, minor_version = tuple(sys.version_info[:2])
patterns = ['python%d%d.dll']
for pat in patterns:
dllname = pat % (major_version, minor_version)
print("Looking for %s" % dllname)
for folder in lib_dirs:
dll = os.path.join(folder, dllname)
if os.path.exists(dll):
return dll
raise ValueError("%s not found in %s" % (dllname, lib_dirs))
示例6: _check_for_import_lib
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def _check_for_import_lib():
"""Check if an import library for the Python runtime already exists."""
major_version, minor_version = tuple(sys.version_info[:2])
# patterns for the file name of the library itself
patterns = ['libpython%d%d.a',
'libpython%d%d.dll.a',
'libpython%d.%d.dll.a']
# directory trees that may contain the library
stems = [sys.prefix]
if hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix:
stems.append(sys.base_prefix)
elif hasattr(sys, 'real_prefix') and sys.real_prefix != sys.prefix:
stems.append(sys.real_prefix)
# possible subdirectories within those trees where it is placed
sub_dirs = ['libs', 'lib']
# generate a list of candidate locations
candidates = []
for pat in patterns:
filename = pat % (major_version, minor_version)
for stem_dir in stems:
for folder in sub_dirs:
candidates.append(os.path.join(stem_dir, folder, filename))
# test the filesystem to see if we can find any of these
for fullname in candidates:
if os.path.isfile(fullname):
# already exists, in location given
return (True, fullname)
# needs to be built, preferred location given first
return (False, candidates[0])
示例7: get_base_prefix
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def get_base_prefix(self): # type: () -> Path
if hasattr(sys, "real_prefix"):
return sys.real_prefix
if hasattr(sys, "base_prefix"):
return sys.base_prefix
return sys.prefix
示例8: finalize_options
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def finalize_options (self):
if self.library_dirs is None:
self.library_dirs = []
elif isinstance(self.library_dirs, basestring):
self.library_dirs = self.library_dirs.split(os.pathsep)
self.library_dirs.insert(0, os.path.join(sys.real_prefix, "Libs"))
old_build_ext.finalize_options(self)
示例9: sysconfig_get_python_inc
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def sysconfig_get_python_inc(plat_specific=0, prefix=None):
if prefix is None:
prefix = sys.real_prefix
return old_get_python_inc(plat_specific, prefix)
示例10: sysconfig_get_python_lib
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def sysconfig_get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
if standard_lib and prefix is None:
prefix = sys.real_prefix
return old_get_python_lib(plat_specific, standard_lib, prefix)
示例11: sysconfig_get_config_vars
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def sysconfig_get_config_vars(*args):
real_vars = old_get_config_vars(*args)
if sys.platform == 'win32':
lib_dir = os.path.join(sys.real_prefix, "libs")
if isinstance(real_vars, dict) and 'LIBDIR' not in real_vars:
real_vars['LIBDIR'] = lib_dir # asked for all
elif isinstance(real_vars, list) and 'LIBDIR' in args:
real_vars = real_vars + [lib_dir] # asked for list
return real_vars
示例12: virtual_addsitepackages
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [as 别名]
def virtual_addsitepackages(known_paths):
force_global_eggs_after_local_site_packages()
return addsitepackages(known_paths, sys_prefix=sys.real_prefix)
示例13: pytest_report_header
# 需要导入模块: import sys [as 别名]
# 或者: from sys import real_prefix [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,))