nojka_kruva
nojka_kruva

Reputation: 1454

Deploying a Python script on a Unix server

I'd like to deploy a Python script on a server and have it executed by the cron task scheduler. My script is not a web service or anything of the sort: it reads stuff from a database, does some computations on it and writes the results back to the database.

What would be the best way to deploy such a script? I've been considering either to make a stand-alone deployment using bbfreeze or to install Python on the target machine and install the script inside a virtualenv. What are the pros and cons of each approach? are there any other approaches I should consider?

Upvotes: 4

Views: 147

Answers (1)

bakkal
bakkal

Reputation: 55448

I think having the script.py + virtualenv on the server is more convenient:

  • You can use version control to update your program
  • You can edit the script while on the UNIX server (e.g. configs, passwords), test it, then commit back to version control
  • No extra steps of bundling the interpreter with the freeze

In which case you just need a cron line like

@daily cd /path && . venv/bin/activate && script.py
                   ^ the dot is like "source", to activate the virtualenv  

Upvotes: 1

Related Questions