10 examples of 'python file to exe' in Python

Every line of 'python file to exe' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
10def exe():
11 return (os.environ.get('BUP_MAIN_EXE') or
12 os.path.join(startdir, sys.argv[0]))
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

89def exec_script(script_filename, env={}, *args):
90 """
91 Executes a Python script in an externally spawned interpreter, and
92 returns anything that was emitted in the standard output as a
93 single string.
94
95 To prevent missuse, the script passed to hookutils.exec_script
96 must be located in the `PyInstaller/utils/hooks/subproc` directory.
97 """
98 script_filename = os.path.basename(script_filename)
99 script_filename = os.path.join(os.path.dirname(__file__), 'subproc', script_filename)
100 if not os.path.exists(script_filename):
101 raise SystemError("To prevent missuse, the script passed to "
102 "hookutils.exec-script must be located in "
103 "the `PyInstaller/utils/hooks/subproc` directory.")
104
105 cmd = [script_filename]
106 cmd.extend(args)
107 return __exec_python_cmd(cmd, env=env)
9def exe(command, shellEnabled=False):
10 print '[EXEC] %s' % command
11 if shellEnabled:
12 process = subprocess.Popen(command, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
13 else:
14 process = subprocess.Popen(shlex.split(command), stderr=subprocess.PIPE, stdout=subprocess.PIPE)
15 output = process.communicate()
16
17 if output[0]:
18 print 'stdout:'
19 print output[0]
20 if output[1]:
21 print 'stderr:'
22 print output[1]
23
24 return output
30def execfile(filename, globals, locals):
31 """Python 3 replacement for ``execfile``."""
32 # Credit: 2to3 and this StackOverflow answer
33 # (http://stackoverflow.com/a/437857/841994) take similar
34 # approaches.
35 with open(filename) as f:
36 code = compile(f.read(), filename, 'exec')
37 exec(code, globals, locals)
851def install_exe(self, dist_filename, tmpdir):
852 # See if it's valid, get data
853 cfg = extract_wininst_cfg(dist_filename)
854 if cfg is None:
855 raise DistutilsError(
856 "%s is not a valid distutils Windows .exe" % dist_filename
857 )
858 # Create a dummy distribution object until we build the real distro
859 dist = Distribution(
860 None,
861 project_name=cfg.get('metadata','name'),
862 version=cfg.get('metadata','version'), platform=get_platform(),
863 )
864
865 # Convert the .exe to an unpacked egg
866 egg_path = dist.location = os.path.join(tmpdir, dist.egg_name()+'.egg')
867 egg_tmp = egg_path + '.tmp'
868 _egg_info = os.path.join(egg_tmp, 'EGG-INFO')
869 pkg_inf = os.path.join(_egg_info, 'PKG-INFO')
870 ensure_directory(pkg_inf) # make sure EGG-INFO dir exists
871 dist._provider = PathMetadata(egg_tmp, _egg_info) # XXX
872 self.exe_to_egg(dist_filename, egg_tmp)
873
874 # Write EGG-INFO/PKG-INFO
875 if not os.path.exists(pkg_inf):
876 f = open(pkg_inf,'w')
877 f.write('Metadata-Version: 1.0\n')
878 for k,v in cfg.items('metadata'):
879 if k != 'target_version':
880 f.write('%s: %s\n' % (k.replace('_','-').title(), v))
881 f.close()
882 script_dir = os.path.join(_egg_info,'scripts')
883 self.delete_blockers( # delete entry-point scripts to avoid duping
884 [os.path.join(script_dir,args[0]) for args in get_script_args(dist)]
885 )
886 # Build .egg file from tmpdir
887 bdist_egg.make_zipfile(
888 egg_path, egg_tmp, verbose=self.verbose, dry_run=self.dry_run
889 )
890 # install the .egg
891 return self.install_egg(egg_path, tmpdir)
319def GetExecutable( filename ):
320 if OnWindows():
321 return _GetWindowsExecutable( filename )
322
323 if ( os.path.isfile( filename )
324 and os.access( filename, EXECUTABLE_FILE_MASK ) ):
325 return filename
326 return None
18def python_switcher(python_exec: str, python_file: str, args: list):
19 '''
20 Switch to the right python
21 '''
22 if not os.getpid() - os.getppid() == 1:
23 subprocess.call(['%s %s %s' % (python_exec, python_file, ' '.join(args))], shell=True)
24 else:
25 sys.exit(1)
76def eval_script(scriptfilename, *args):
77 txt = exec_script(scriptfilename, *args).strip()
78 if not txt:
79 # return an empty string which is "not true" but iterable
80 return ''
81 return eval(txt)
193def execfile(filename, device='/dev/ttyACM0', baudrate=115200, user='micro', password='python'):
194 pyb = Pyboard(device, baudrate, user, password)
195 pyb.enter_raw_repl()
196 output = pyb.execfile(filename)
197 stdout_write_bytes(output)
198 pyb.exit_raw_repl()
199 pyb.close()
7def execfile3(file, globals=globals(), locals=locals()):
8 with open(file, "r") as fh:
9 exec(fh.read()+"\n", globals, locals)

Related snippets