Create a gist now

Instantly share code, notes, and snippets.

Python 3 64bits deployment script
# Almost copied entirely from http://www.clemens-sielaff.com/creating-your-own-python-3-redistributable-on-windows/
import os, sys
from glob import glob
from shutil import copy, copytree
RELEASE = 1
DEBUG = 2
def find_visual_studio():
candidates = [entry for entry in os.environ.values() if "Common7" in entry]
for candidate in candidates:
candidate = os.path.normpath(candidate)
if not os.path.isdir(candidate):
continue
return candidate[:candidate.find("Common7")]
raise ValueError
def copy_redistributable(install_type, INSTALL_PATH):
try:
base_path = find_visual_studio()
if install_type == DEBUG:
library_path = os.path.join(base_path, r"VC\redist\Debug_NonRedist\x86\Microsoft.VC110.DebugCRT\msvcr110d.dll")
else:
library_path = os.path.join(base_path, r"VC\redist\x86\Microsoft.VC110.CRT\msvcr110.dll")
copy(library_path, INSTALL_PATH)
except:
print("Cannot find Microsoft Visual Studio installation directory.")
print("You have to copy msvcr110%s.dll manually into the installation directory." % ("d" if install_type == DEBUG else ""))
def make(install_type, install_dir="_INSTALL"):
debug_extension = "_d" if install_type == DEBUG else ""
CWD = os.getcwd()
INSTALL_PATH = os.path.join(CWD, install_dir + debug_extension)
PCBUILD_PATH = os.path.join(CWD, "PCbuild/amd64")
PC_PATH = os.path.join(CWD, "PC")
# copy files in the main directory
os.mkdir(INSTALL_PATH)
copy_redistributable(install_type, INSTALL_PATH)
for file_name in [
"python%s.exe" % debug_extension,
"python34%s.dll" % debug_extension,
"pythonw%s.exe" % debug_extension,
"py%s.exe" % debug_extension,
"pyw%s.exe" % debug_extension,
]:
copy(os.path.join(PCBUILD_PATH, file_name), INSTALL_PATH)
# copy files in the DLLs directory
DLLS_PATH = os.path.join(INSTALL_PATH, "DLLs")
os.mkdir(DLLS_PATH)
if install_type == RELEASE:
copy_list = [path_name for path_name in glob(os.path.join(PCBUILD_PATH, "*.pyd")) if not path_name.endswith("_d.pyd")]
else:
copy_list = [path_name for path_name in glob(os.path.join(PCBUILD_PATH, "*_d.pyd"))]
for path_name in copy_list:
if os.path.basename(path_name) in [
"xxlimited%s.pyd" % debug_extension,
]: continue
copy(path_name, DLLS_PATH)
for file_name in [
"py.ico",
"pyc.ico",
]:
copy(os.path.join(PC_PATH, file_name), DLLS_PATH)
for file_name in [
"python3.dll",
"sqlite3%s.dll" % debug_extension,
]:
copy(os.path.join(PCBUILD_PATH, file_name), DLLS_PATH)
# copy files in the include directory
INCLUDE_PATH = os.path.join(INSTALL_PATH, "include")
os.mkdir(INCLUDE_PATH)
for path_name in glob(os.path.join(os.path.join(CWD, "Include"), "*.h")):
copy(path_name, INCLUDE_PATH)
copy(os.path.join(PC_PATH, "pyconfig.h"), INCLUDE_PATH)
# copy files in the LIB directory
LIB_PATH = os.path.join(INSTALL_PATH, "Lib")
PYLIB_PATH = os.path.join(CWD, "Lib")
os.mkdir(LIB_PATH)
for path_name in glob(os.path.join(PYLIB_PATH, "*.py")):
copy(path_name, LIB_PATH)
copy_dirs = next(os.walk(PYLIB_PATH))[1]
for directory_name in copy_dirs:
if directory_name.startswith("plat-") or directory_name in [
"idlelib",
"tkinter",
"turtledemo",
]: continue
copytree(os.path.join(PYLIB_PATH, directory_name), os.path.join(LIB_PATH, directory_name))
# copy files in the libs directory
LIBS_PATH = os.path.join(INSTALL_PATH, "libs")
os.mkdir(LIBS_PATH)
if install_type == RELEASE:
copy_list = [path_name for path_name in glob(os.path.join(PCBUILD_PATH, "*.lib")) if not path_name.endswith("_d.lib")]
else:
copy_list = [path_name for path_name in glob(os.path.join(PCBUILD_PATH, "*_d.lib"))]
copy_list.append(os.path.join(PCBUILD_PATH, "python3.lib"))
for path_name in copy_list:
if os.path.basename(path_name) in [
"python34stub%s.lib" % debug_extension,
"xxlimited%s.lib" % debug_extension,
]: continue
copy(path_name, LIBS_PATH)
def main():
success = False
if "Release" in sys.argv:
make(RELEASE)
success = True
if "Debug" in sys.argv:
make(DEBUG)
success = True
if not success:
print("Specify installation type by passing 'Release' and / or 'Debug' as script arguments")
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment