本文整理汇总了Python中pip.__file__方法的典型用法代码示例。如果您正苦于以下问题:Python pip.__file__方法的具体用法?Python pip.__file__怎么用?Python pip.__file__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip
的用法示例。
在下文中一共展示了pip.__file__方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_mxnet
# 需要导入模块: import pip [as 别名]
# 或者: from pip import __file__ [as 别名]
def check_mxnet():
print('----------MXNet Info-----------')
try:
import mxnet
print('Version :', mxnet.__version__)
mx_dir = os.path.dirname(mxnet.__file__)
print('Directory :', mx_dir)
commit_hash = os.path.join(mx_dir, 'COMMIT_HASH')
with open(commit_hash, 'r') as f:
ch = f.read().strip()
print('Commit Hash :', ch)
except ImportError:
print('No MXNet installed.')
except IOError:
print('Hashtag not found. Not installed from pre-built package.')
except Exception as e:
import traceback
if not isinstance(e, IOError):
print("An error occured trying to import mxnet.")
print("This is very likely due to missing missing or incompatible library files.")
print(traceback.format_exc())
示例2: main
# 需要导入模块: import pip [as 别名]
# 或者: from pip import __file__ [as 别名]
def main():
parser = ArgumentParser()
parser.add_argument("dist_name")
parser.add_argument("--index-url", "-i")
parser.add_argument("--extra-index-url")
parser.add_argument("--for-python", "-p", dest="env", type=python_interpreter)
parser.add_argument("--verbose", "-v", default=1, type=int, choices=range(3))
debug = {
"sys.argv": sys.argv,
"sys.executable": sys.executable,
"sys.version": sys.version,
"sys.path": sys.path,
"pip.__version__": pip.__version__,
"pip.__file__": pip.__file__,
}
args = parser.parse_args()
configure_logging(verbosity=args.verbose)
log.debug("runtime info", **debug)
result = get(dist_name=args.dist_name, index_url=args.index_url, env=args.env, extra_index_url=args.extra_index_url)
text = json.dumps(result, indent=2, sort_keys=True, separators=(",", ": "))
print(text)
示例3: create_vendor_txt_map
# 需要导入模块: import pip [as 别名]
# 或者: from pip import __file__ [as 别名]
def create_vendor_txt_map():
# type: () -> Dict[str, str]
vendor_txt_path = os.path.join(
os.path.dirname(pip_location),
'_vendor',
'vendor.txt'
)
with open(vendor_txt_path) as f:
# Purge non version specifying lines.
# Also, remove any space prefix or suffixes (including comments).
lines = [line.strip().split(' ', 1)[0]
for line in f.readlines() if '==' in line]
# Transform into "module" -> version dict.
return dict(line.split('==', 1) for line in lines) # type: ignore
示例4: check_pip
# 需要导入模块: import pip [as 别名]
# 或者: from pip import __file__ [as 别名]
def check_pip():
print('------------Pip Info-----------')
try:
import pip
print('Version :', pip.__version__)
print('Directory :', os.path.dirname(pip.__file__))
except ImportError:
print('No corresponding pip install for current python.')
示例5: install_requirements
# 需要导入模块: import pip [as 别名]
# 或者: from pip import __file__ [as 别名]
def install_requirements(
self,
finder, # type: PackageFinder
requirements, # type: Iterable[str]
prefix_as_string, # type: str
message # type: Optional[str]
):
# type: (...) -> None
prefix = self._prefixes[prefix_as_string]
assert not prefix.setup
prefix.setup = True
if not requirements:
return
args = [
sys.executable, os.path.dirname(pip_location), 'install',
'--ignore-installed', '--no-user', '--prefix', prefix.path,
'--no-warn-script-location',
] # type: List[str]
if logger.getEffectiveLevel() <= logging.DEBUG:
args.append('-v')
for format_control in ('no_binary', 'only_binary'):
formats = getattr(finder.format_control, format_control)
args.extend(('--' + format_control.replace('_', '-'),
','.join(sorted(formats or {':none:'}))))
if finder.index_urls:
args.extend(['-i', finder.index_urls[0]])
for extra_index in finder.index_urls[1:]:
args.extend(['--extra-index-url', extra_index])
else:
args.append('--no-index')
for link in finder.find_links:
args.extend(['--find-links', link])
for _, host, _ in finder.secure_origins:
args.extend(['--trusted-host', host])
if finder.allow_all_prereleases:
args.append('--pre')
args.append('--')
args.extend(requirements)
with open_spinner(message) as spinner:
call_subprocess(args, spinner=spinner)
示例6: install_requirements
# 需要导入模块: import pip [as 别名]
# 或者: from pip import __file__ [as 别名]
def install_requirements(
self,
finder, # type: PackageFinder
requirements, # type: Iterable[str]
prefix_as_string, # type: str
message # type: Optional[str]
):
# type: (...) -> None
prefix = self._prefixes[prefix_as_string]
assert not prefix.setup
prefix.setup = True
if not requirements:
return
args = [
sys.executable, os.path.dirname(pip_location), 'install',
'--ignore-installed', '--no-user', '--prefix', prefix.path,
'--no-warn-script-location',
] # type: List[str]
if logger.getEffectiveLevel() <= logging.DEBUG:
args.append('-v')
for format_control in ('no_binary', 'only_binary'):
formats = getattr(finder.format_control, format_control)
args.extend(('--' + format_control.replace('_', '-'),
','.join(sorted(formats or {':none:'}))))
if finder.index_urls:
args.extend(['-i', finder.index_urls[0]])
for extra_index in finder.index_urls[1:]:
args.extend(['--extra-index-url', extra_index])
else:
args.append('--no-index')
for link in finder.find_links:
args.extend(['--find-links', link])
for _, host, _ in finder.secure_origins:
args.extend(['--trusted-host', host])
if finder.allow_all_prereleases:
args.append('--pre')
args.append('--')
args.extend(requirements)
with open_spinner(message) as spinner:
call_subprocess(args, show_stdout=False, spinner=spinner)
示例7: prepare_virtualenv
# 需要导入模块: import pip [as 别名]
# 或者: from pip import __file__ [as 别名]
def prepare_virtualenv(path=None, callback=None, wait=False):
if path is None:
path = g['path']['virtualenv']
abspath = os.path.abspath(path)
sys.path.insert(0, abspath)
if not wait and callback:
def callback(): return __work(callback)
try:
activator_path = os.path.join(
abspath, 'Scripts' if sys.platform == 'win32' else 'bin', 'activate_this.py')
if not os.path.isfile(activator_path):
raise ImportError()
runpy.run_path(activator_path)
callback and callback()
except ImportError:
tasks = [
lambda: prepare_virtualenv(path)
]
try:
import pip
if not os.path.abspath(pip.__file__).startswith(abspath):
raise ImportError()
except ImportError:
log.info(
'Will install virtualenv at %r since pip module is not found...', path)
tasks.insert(0, lambda: _install_virtualenv(path))
def handler(): return ([task()
for task in tasks], callback and callback())
__work(handler) if not wait else handler()
示例8: install_requirements
# 需要导入模块: import pip [as 别名]
# 或者: from pip import __file__ [as 别名]
def install_requirements(
self,
finder, # type: PackageFinder
requirements, # type: Iterable[str]
prefix_as_string, # type: str
message # type: Optional[str]
):
# type: (...) -> None
prefix = self._prefixes[prefix_as_string]
assert not prefix.setup
prefix.setup = True
if not requirements:
return
args = [
sys.executable, os.path.dirname(pip_location), 'install',
'--ignore-installed', '--no-user', '--prefix', prefix.path,
'--no-warn-script-location',
] # type: List[str]
if logger.getEffectiveLevel() <= logging.DEBUG:
args.append('-v')
for format_control in ('no_binary', 'only_binary'):
formats = getattr(finder.format_control, format_control)
args.extend(('--' + format_control.replace('_', '-'),
','.join(sorted(formats or {':none:'}))))
index_urls = finder.index_urls
if index_urls:
args.extend(['-i', index_urls[0]])
for extra_index in index_urls[1:]:
args.extend(['--extra-index-url', extra_index])
else:
args.append('--no-index')
for link in finder.find_links:
args.extend(['--find-links', link])
for host in finder.trusted_hosts:
args.extend(['--trusted-host', host])
if finder.allow_all_prereleases:
args.append('--pre')
args.append('--')
args.extend(requirements)
with open_spinner(message) as spinner:
call_subprocess(args, spinner=spinner)