Skip to content

Instantly share code, notes, and snippets.

@ruoyu0088
Created August 12, 2015 08:37
Show Gist options
  • Save ruoyu0088/96ef095a41e398277d03 to your computer and use it in GitHub Desktop.
Save ruoyu0088/96ef095a41e398277d03 to your computer and use it in GitHub Desktop.
from pip import _vendor
import os
from io import BytesIO
ScriptMaker = _vendor.distlib.scripts.ScriptMaker
ZipFile = _vendor.distlib.compat.ZipFile
sm = ScriptMaker("", "")
launcher = sm._get_launcher("t")
shebang = sm._get_shebang('utf-8', b"")
linesep = os.linesep.encode('utf-8')
script_bytes = b"""
from notebook.notebookapp import main
if __name__ == '__main__':
main()
"""
stream = BytesIO()
with ZipFile(stream, 'w') as zf:
zf.writestr('__main__.py', script_bytes)
zip_data = stream.getvalue()
script_bytes = launcher + shebang + linesep + zip_data
with open(r"C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\Scripts\jupyter-notebook.exe", "wb") as f:
f.write(script_bytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment