本文整理匯總了Python中sys.executable方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.executable方法的具體用法?Python sys.executable怎麽用?Python sys.executable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sys
的用法示例。
在下文中一共展示了sys.executable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_interpreter_argv
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def _get_interpreter_argv():
"""Retrieve current Python interpreter's arguments.
Returns empty tuple in case of frozen mode, uses built-in arguments
reproduction function otherwise.
Frozen mode is possible for the app has been packaged into a binary
executable using py2exe. In this case the interpreter's arguments are
already built-in into that executable.
:seealso: https://github.com/cherrypy/cherrypy/issues/1526
Ref: https://pythonhosted.org/PyInstaller/runtime-information.html
"""
return ([]
if getattr(sys, 'frozen', False)
else subprocess._args_from_interpreter_flags())
示例2: run
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def run(self):
try:
self.status('Removing previous builds…')
rmtree(os.path.join(here, 'dist'))
except OSError:
pass
self.status('Building Source and Wheel (universal) distribution…')
os.system('{0} setup.py sdist bdist_wheel --universal'.format(
sys.executable
))
self.status('Uploading the package to PyPi via Twine…')
os.system('twine upload dist/*')
sys.exit()
示例3: main
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def main():
env = os.environ.copy()
# in case the PYTHONHASHSEED was not set, set to 0 to denote
# that hash randomization should be disabled and
# restart python for the changes to take effect
if 'PYTHONHASHSEED' not in env:
env['PYTHONHASHSEED'] = "0"
proc = subprocess.Popen([sys.executable] + sys.argv,
env=env)
proc.communicate()
exit(proc.returncode)
# check if hash has been properly de-randomized in python 3
# by comparing hash of magic tuple
h = hash(eden.__magic__)
assert h == eden.__magic_py2hash__ or h == eden.__magic_py3hash__, 'Unexpected hash value: "{}". Please check if python 3 hash normalization is disabled by setting shell variable PYTHONHASHSEED=0.'.format(h)
# run program and exit
print("This is the magic python hash restart script.")
exit(0)
示例4: run
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def run(self):
try:
self.status('Removing previous builds...')
rmtree(os.path.join(base_path, 'dist'))
except OSError:
pass
self.status('Building Source and Wheel (universal) distribution...')
os.system('{0} setup.py sdist bdist_wheel'.format(sys.executable))
self.status('Pushing git tags...')
os.system('git tag v{0}'.format(get_version()))
os.system('git push --tags')
try:
self.status('Removing build artifacts...')
rmtree(os.path.join(base_path, 'build'))
rmtree(os.path.join(base_path, '{}.egg-info'.format(PACKAGE_NAME)))
except OSError:
pass
sys.exit()
示例5: manage
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def manage():
def call(*args, **kwargs):
ignore_errors = kwargs.pop("ignore_errors", False)
assert not kwargs
cmd = [
sys.executable,
os.path.join(os.path.dirname(__file__), "testprj", "manage.py"),
] + list(args)
try:
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
if not ignore_errors:
raise
return e.output
return call
示例6: shutdown
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def shutdown():
if lp_events.timer != None:
lp_events.timer.cancel()
scripts.to_run = []
for x in range(9):
for y in range(9):
if scripts.threads[x][y] != None:
scripts.threads[x][y].kill.set()
if window.lp_connected:
scripts.unbind_all()
lp_events.timer.cancel()
launchpad_connector.disconnect(lp)
window.lp_connected = False
logger.stop()
if window.restart:
if IS_EXE:
os.startfile(sys.argv[0])
else:
os.execv(sys.executable, ["\"" + sys.executable + "\""] + sys.argv)
sys.exit("[LPHK] Shutting down...")
示例7: save_pyoptix_conf
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def save_pyoptix_conf(nvcc_path, compile_args, include_dirs, library_dirs, libraries):
try:
config = ConfigParser()
config.add_section('pyoptix')
config.set('pyoptix', 'nvcc_path', nvcc_path)
config.set('pyoptix', 'compile_args', os.pathsep.join(compile_args))
config.set('pyoptix', 'include_dirs', os.pathsep.join(include_dirs))
config.set('pyoptix', 'library_dirs', os.pathsep.join(library_dirs))
config.set('pyoptix', 'libraries', os.pathsep.join(libraries))
tmp = NamedTemporaryFile(mode='w+', delete=False)
config.write(tmp)
tmp.close()
config_path = os.path.join(os.path.dirname(sys.executable), 'pyoptix.conf')
check_call_sudo_if_fails(['cp', tmp.name, config_path])
check_call_sudo_if_fails(['cp', tmp.name, '/etc/pyoptix.conf'])
check_call_sudo_if_fails(['chmod', '644', config_path])
check_call_sudo_if_fails(['chmod', '644', '/etc/pyoptix.conf'])
except Exception as e:
print("PyOptiX configuration could not be saved. When you use pyoptix.Compiler, "
"nvcc path must be in PATH, OptiX library paths must be in LD_LIBRARY_PATH, and pyoptix.Compiler "
"attributes should be set manually.")
示例8: test_patch_wheel
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def test_patch_wheel():
# Check patching of wheel
with InTemporaryDirectory():
# First wheel needs proper wheel filename for later unpack test
out_fname = basename(PURE_WHEEL)
patch_wheel(PURE_WHEEL, WHEEL_PATCH, out_fname)
zip2dir(out_fname, 'wheel1')
with open(pjoin('wheel1', 'fakepkg2', '__init__.py'), 'rt') as fobj:
assert_equal(fobj.read(), 'print("Am in init")\n')
# Check that wheel unpack works
back_tick([sys.executable, '-m', 'wheel', 'unpack', out_fname])
# Copy the original, check it doesn't have patch
shutil.copyfile(PURE_WHEEL, 'copied.whl')
zip2dir('copied.whl', 'wheel2')
with open(pjoin('wheel2', 'fakepkg2', '__init__.py'), 'rt') as fobj:
assert_equal(fobj.read(), '')
# Overwrite input wheel (the default)
patch_wheel('copied.whl', WHEEL_PATCH)
# Patched
zip2dir('copied.whl', 'wheel3')
with open(pjoin('wheel3', 'fakepkg2', '__init__.py'), 'rt') as fobj:
assert_equal(fobj.read(), 'print("Am in init")\n')
# Check bad patch raises error
assert_raises(RuntimeError,
patch_wheel, PURE_WHEEL, WHEEL_PATCH_BAD, 'out.whl')
示例9: mpi_fork
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def mpi_fork(n, bind_to_core=False):
"""Re-launches the current script with workers
Returns "parent" for original parent, "child" for MPI children
"""
if n<=1:
return "child"
if os.getenv("IN_MPI") is None:
env = os.environ.copy()
env.update(
MKL_NUM_THREADS="1",
OMP_NUM_THREADS="1",
IN_MPI="1"
)
args = ["mpirun", "-np", str(n)]
if bind_to_core:
args += ["-bind-to", "core"]
args += [sys.executable] + sys.argv
subprocess.check_call(args, env=env)
return "parent"
else:
return "child"
示例10: test_build_calmjs_artifact
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def test_build_calmjs_artifact(self):
"""
Emulate the execution of ``python setup.py egg_info``.
Ensure everything is covered.
"""
# run the step directly to see that the command is registered,
# though the actual effects cannot be tested, as the test
# package is not going to be installed and there are no valid
# artifact build functions defined.
p = Popen(
[sys.executable, 'setup.py', 'build_calmjs_artifacts'],
stdout=PIPE, stderr=PIPE, cwd=self.pkg_root,
)
stdout, stderr = p.communicate()
stdout = stdout.decode(locale)
self.assertIn('running build_calmjs_artifacts', stdout)
示例11: run
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def run(self):
try:
self.status('Removing previous builds…')
rmtree(os.path.join(here, 'dist'))
except OSError:
pass
self.status('Building Source and Wheel (universal) distribution…')
os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable))
self.status('Uploading the package to PyPi via Twine…')
os.system('twine upload dist/*')
self.status('Pushing git tags…')
os.system('git tag v{0}'.format(about['__version__']))
os.system('git push --tags')
sys.exit()
# Where the magic happens:
示例12: mpi_fork
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def mpi_fork(n, extra_mpi_args=[]):
"""Re-launches the current script with workers
Returns "parent" for original parent, "child" for MPI children
"""
if n <= 1:
return "child"
if os.getenv("IN_MPI") is None:
env = os.environ.copy()
env.update(
MKL_NUM_THREADS="1",
OMP_NUM_THREADS="1",
IN_MPI="1"
)
# "-bind-to core" is crucial for good performance
args = ["mpirun", "-np", str(n)] + \
extra_mpi_args + \
[sys.executable]
args += sys.argv
subprocess.check_call(args, env=env)
return "parent"
else:
install_mpi_excepthook()
return "child"
示例13: read_config
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def read_config():
_dict = {}
if getattr(sys, 'frozen', None):
config_path = os.path.join(os.path.dirname(sys.executable), 'config', 'config.ini')
else:
config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'config.ini')
if not os.path.exists(config_path):
print('can not find the config.ini, use the default sm uploader.'
'attention: this website may breakdown in the future, only used temporarily.')
_dict['picture_host'] = 'SmUploader'
return _dict
configs = ConfigParser()
configs.read(config_path)
_dict['picture_folder'] = configs['basic'].get('picture_folder', '')
_dict['picture_suffix'] = configs['basic'].get('picture_suffix', '')
_dict['picture_host'] = configs['basic'].get('picture_host', '')
_dict['config_path'] = config_path
if _dict['picture_host']:
_dict['uploader_info'] = configs[_dict['picture_host']]
return _dict
示例14: test
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def test(coverage=False):
"""Run the unit tests."""
if coverage and not os.environ.get('FLASK_COVERAGE'):
import sys
os.environ['FLASK_COVERAGE'] = '1'
os.execvp(sys.executable, [sys.executable] + sys.argv)
import unittest
import xmlrunner
tests = unittest.TestLoader().discover('tests')
# run tests with unittest-xml-reporting and output to $CIRCLE_TEST_REPORTS on CircleCI or test-reports locally
xmlrunner.XMLTestRunner(output=os.environ.get('CIRCLE_TEST_REPORTS','test-reports')).run(tests)
if COV:
COV.stop()
COV.save()
print('Coverage Summary:')
COV.report()
basedir = os.path.abspath(os.path.dirname(__file__))
covdir = os.path.join(basedir, 'tmp/coverage')
COV.html_report(directory=covdir)
print('HTML version: file://%s/index.html' % covdir)
COV.erase()
示例15: get_resource_path
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import executable [as 別名]
def get_resource_path(*args):
if is_frozen():
# MEIPASS explanation:
# https://pythonhosted.org/PyInstaller/#run-time-operation
basedir = getattr(sys, '_MEIPASS', None)
if not basedir:
basedir = os.path.dirname(sys.executable)
resource_dir = os.path.join(basedir, 'gooey')
if not os.path.isdir(resource_dir):
raise IOError(
("Cannot locate Gooey resources. It seems that the program was frozen, "
"but resource files were not copied into directory of the executable "
"file. Please copy `languages` and `images` folders from gooey module "
"directory into `{}{}` directory. Using PyInstaller, a.datas in .spec "
"file must be specified.".format(resource_dir, os.sep)))
else:
resource_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', '..'))
return os.path.join(resource_dir, *args)