Skip to content

Instantly share code, notes, and snippets.

@SegFaultAX
Last active January 2, 2022 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SegFaultAX/2c010063939a4d0712e6 to your computer and use it in GitHub Desktop.
Save SegFaultAX/2c010063939a4d0712e6 to your computer and use it in GitHub Desktop.
Install any package to coderpad
def main():
# Application code goes here!
pass
PACKAGES = ("praw", )
### IGNORE BELOW THIS LINE ###
def run(cmd, shell=False, silent=False):
import subprocess, shlex, os
args = shlex.split(cmd)
if silent:
with open(os.devnull) as DEVNULL:
return subprocess.call(args, stdout=DEVNULL, stderr=subprocess.STDOUT)
else:
subprocess.call(args, shell=shell)
def do_packages(package, *packages):
import sys, os
all_packages = (package,) + packages
print "Installing packages: {}".format(", ".join(all_packages))
user = os.environ.get("HOME")
site_packages = os.path.join(user, ".local/lib/python2.7/site-packages")
sys.path.append(site_packages)
run("pip install --user {}".format(" ".join((package,) + packages)), silent=True)
def go(args=""):
if PACKAGES:
do_packages(*PACKAGES)
print "Setup complete... Running main.\n\n\n"
run("python /home/coderpad/solution.py GOGO {}".format(args))
import sys
if len(sys.argv) > 1 and sys.argv[1] == "GOGO":
sys.argv.pop(0)
main()
else:
print "Run go() in the REPL to run your program!"
@Ali1Almakhmari
Copy link

Ali1Almakhmari commented Jan 2, 2022

I don't understand how to use this. For example, how does this help if I want to install the matplotlib library in CoderPad?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment