""" Installs IPython on Pyto. Usage: Usage: import requests as r; exec(r.get('https://bit.ly/35iSbM1').content.decode()) """ from pip import main as pip from wget import main as wget from unzip import main as unzip import shutil import os.path docs = os.path.expanduser("~/Documents") site_packages = os.path.join(docs, "site-packages") bin = os.path.join(docs, "stash_extensions/bin") if not os.path.exists(site_packages): os.makedirs(site_packages) # Install 'ptyprocess', fails with pip ptyprocess_zip = os.path.join(docs, "ptyprocess.zip") ptyprocess_unzipped = os.path.join(docs, "ptyprocess-master") wget(["https://github.com/pexpect/ptyprocess/archive/master.zip", "--output-file", ptyprocess_zip]) unzip([ptyprocess_zip, "--exdir", ptyprocess_unzipped]) try: shutil.move(os.path.join(ptyprocess_unzipped, "ptyprocess"), os.path.join(site_packages, "ptyprocess")) shutil.rmtree(ptyprocess_unzipped) except shutil.Error: pass # Install IPython try: pip(["install", "ipython"]) except: pass if not os.path.exists(bin): os.makedirs(bin) # Disable SyntaxWarning runner = """'''???''' import warnings import code import console def start(banner=None, readfunc=None, local=None, exitmsg=None): with warnings.catch_warnings(record=True) as w: from IPython import start_ipython start_ipython() code.interact = start console.interact = start if __name__ == "__main__": start() """ with open(os.path.join(bin, "ipython.py"), 'w') as f: f.write(runner) with open(os.path.join(bin, "ipython3.py"), 'w') as f: f.write(runner) print("") print("Restart Pyto to launch IPython shell. IPython can be executed from the script in ~/Documents/stash_extensions/bin/ipython.py, from the 'Run module' section or just by importing it.")