Python sys.real_prefix() Examples
The following are 30
code examples of sys.real_prefix().
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
sys
, or try the search function
.
Example #1
Source File: poetry_api.py From trains-agent with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: pydeps2requirements.py From pydeps with BSD 2-Clause "Simplified" License | 6 votes |
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))
Example #3
Source File: a10_config.py From a10-neutron-lbaas with Apache License 2.0 | 6 votes |
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
Example #4
Source File: __init__.py From scylla with Apache License 2.0 | 5 votes |
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
Example #5
Source File: __init__.py From mxnet-lambda with Apache License 2.0 | 5 votes |
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)
Example #6
Source File: __init__.py From Flask-P2P with MIT License | 5 votes |
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)
Example #7
Source File: __init__.py From Flask-P2P with MIT License | 5 votes |
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)
Example #8
Source File: conf.py From theanolm with Apache License 2.0 | 5 votes |
def create_apidoc(_): """A workaround for running sphinx-apidoc on Read the Docs. """ if hasattr(sys, 'real_prefix'): # In a virtualenv sys.prefix points to the virtualenv directory and # sys.real_prefix points to the system prefix. cmd = path.abspath(path.join(sys.prefix, 'bin', 'sphinx-apidoc')) else: cmd = 'sphinx-apidoc' environ['SPHINX_APIDOC_OPTIONS'] = \ 'members,special-members,private-members,undoc-members,show-inheritance' subprocess.check_call( [cmd, '--force', '--no-toc', '-o', docs_dir, root_dir, setup_path, tests_dir])
Example #9
Source File: site.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def virtual_addsitepackages(known_paths): force_global_eggs_after_local_site_packages() return addsitepackages(known_paths, sys_prefix=sys.real_prefix)
Example #10
Source File: __init__.py From mxnet-lambda with Apache License 2.0 | 5 votes |
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)
Example #11
Source File: __init__.py From mxnet-lambda with Apache License 2.0 | 5 votes |
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)
Example #12
Source File: __init__.py From addon with GNU General Public License v3.0 | 5 votes |
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``.
Example #13
Source File: __init__.py From telegram-robot-rss with Mozilla Public License 2.0 | 5 votes |
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)
Example #14
Source File: __init__.py From telegram-robot-rss with Mozilla Public License 2.0 | 5 votes |
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)
Example #15
Source File: __init__.py From telegram-robot-rss with Mozilla Public License 2.0 | 5 votes |
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``.
Example #16
Source File: site.py From scylla with Apache License 2.0 | 5 votes |
def virtual_addsitepackages(known_paths): force_global_eggs_after_local_site_packages() return addsitepackages(known_paths, sys_prefix=sys.real_prefix)
Example #17
Source File: __init__.py From telegram-robot-rss with Mozilla Public License 2.0 | 5 votes |
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
Example #18
Source File: __init__.py From scylla with Apache License 2.0 | 5 votes |
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)
Example #19
Source File: __init__.py From scylla with Apache License 2.0 | 5 votes |
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)
Example #20
Source File: __init__.py From scylla with Apache License 2.0 | 5 votes |
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)
Example #21
Source File: mingw32ccompiler.py From pySINDy with MIT License | 5 votes |
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])
Example #22
Source File: mingw32ccompiler.py From pySINDy with MIT License | 5 votes |
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))
Example #23
Source File: mingw32ccompiler.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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])
Example #24
Source File: mingw32ccompiler.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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))
Example #25
Source File: site.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def virtual_addsitepackages(known_paths): force_global_eggs_after_local_site_packages() return addsitepackages(known_paths, sys_prefix=sys.real_prefix)
Example #26
Source File: __init__.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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)
Example #27
Source File: __init__.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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)
Example #28
Source File: __init__.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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)
Example #29
Source File: mingw32ccompiler.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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])
Example #30
Source File: mingw32ccompiler.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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))