Creating Python Cron Job On Synology: Difference between revisions
No edit summary |
|||
| Line 63: | Line 63: | ||
The more recent DiskStation on the other hand was able to install `lxml` right away with pip. | The more recent DiskStation on the other hand was able to install `lxml` right away with pip. | ||
For instructions on how to install python packages from GitHub see wiki article on [[Python_Packaging#Installation_from_GitHub|Installing Python Packages from GitHub]]. | |||
== Notes == | == Notes == | ||
<references /> | <references /> | ||
Revision as of 09:55, 1 April 2018
Objective
To install a python script on Synology NAS and run it as a cron job.
Prerequisites
Git
Git is needed if python packages are installed from GitHub.
DSM > Package Center > Utilities > Third-Party > GIT Server > Install
python
Install Python3 using the Package Center app in the DSM.
pip
SSH to the DiskStation and install pip with
$ wget https://bootstrap.pypa.io/get-pip.py $ sudo python3 get-pip.py $ rm get-pip.py
This will install pip at /volume1/@appstore/py3k/usr/local/bin/, but the pip command isn't automatically available.
$ pip -sh: pip: command not found $ sudo ln -s /volume1/@appstore/py3k/usr/local/bin/pip /usr/local/bin/pip $pip --version pip 9.0.3 from /volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages (python 3.5)
virtualenv
Once pip is installed, use it to install virtualenv, and make sure the command is available from the command line:
$ sudo pip install virtualenv $ sudo ln -s /volume1/@appstore/py3k/usr/local/bin/virtualenv /usr/local/bin/virtualenv
Create a virtual environment for the python script:
$ virtualenv -p /volume1/@appstore/py3k/usr/local/bin/python3 venv
SSH key for GitHub
- Generate a SSH key
- Add the SSH key to the GitHub acccount
- The instructions on that page say to use
apt-getto installxclip.apt-getis not available on Synology. [1]xclipis being installed to copy the contents of the ssh key file from the command line, howeverxclipdoesn't seem to be readily available for Synology, so open up the key file and manually copy its contents instead.
- The instructions on that page say to use
Installing python packages
I experienced an issue on DS213 where at least one PyPI package (lxml) could not be compiled. Something to the effect that there was no gcc or cc compiler available. Not sure why a python package needs that, but I spent a while trying to install the various things that were reported missing without ultimately succeeding.
The more recent DiskStation on the other hand was able to install lxml right away with pip.
For instructions on how to install python packages from GitHub see wiki article on Installing Python Packages from GitHub.