Install Python in Synology · Python

Install and use Python 3.9 in your Synology

One of the advantages of installing python in your Synology is that you can write and schedule python scripts.

In this post I will show you how to get python 3.9 running, but in a future post I will show you how to schedule it.

Enable Home for all users

First, lets enable home for all users. That is where your python scripts will reside.

Enable SSH

I recommend you to disable SSH when you are done because it disables 2 factor auth and makes your synology more vulnerable.

Go to Control Panel > Terminal & SNMP > Terminal tab:

  1. Check “Enable SSH service”
  2. Click “Apply”

Run SSH

Before we run SSH, we need to know the IP of the server:

So now Press the windows icon and type cmd to start the cmd prompt and type:

username is your admin username.

ssh username@192.168.1.xx

Enter your admin password and you are in!

Upgrade Python

All synologies come with python 2 pre-install, but we want to use python 3. Lets upgrade it from the package center:

You will find your python 3.9 here:

/volume1/\@appstore/Python3.9/usr/bin/python3.9

If you look in the site-packages directory, you will see it is empty:

ls /volume1/\@appstore/Python3.9/usr/lib/python3.9/site-packages

so we need to install pip.

Either add the python3.9 to PATH or specify it when installing.

Sudo makes it available for all users. Your choice.

sudo /volume1/\@appstore/Python3.9/usr/bin/python3.9 -m ensurepip

Check if it has been installed:

ls /volume1/\@appstore/Python3.9/usr/lib/python3.9/site-packages

You should see pip there:

Update the pip, setuptools and wheel packages:

sudo /volume1/\@appstore/Python3.9/usr/bin/python3.9 -m pip install --upgrade pip setuptools wheel

And now install virtual environment:

sudo /volume1/\@appstore/Python3.9/usr/bin/python3.9 -m pip install virtualenv

and verify it is there:

ls /volume1/\@appstore/Python3.9/usr/lib/python3.9/site-packages

Now we are going to create a folder on our home directory

mkdir el_tracker

If you now navigate to your Home folder, you will see the folder there:

Navigate to the folder:

cd el_tracker

and create the virtual environment:

Note: elenv is the name of our virtual environment.

python3 -m venv elenv

And now you can activate it:

source elenv/bin/activate

Now that we are inside the environment we can install the packages we need.

The easiest way to get this done is to create a requirements.txt file and save it on your el_tracker project folder.

This is how the file looks like:

To get all those packages installed at once:

pip install -r requirements.txt

Now you installed everything:

  1. Close the cmd window
  2. Disable SSH
  3. Make sure 2FA is still enabled

and happy python coding!

Coming next….

On my next post I will show you how to schedule your python script on your NAS.

Advertisement

4 thoughts on “Install and use Python 3.9 in your Synology

  1. Thanks Ruth, much appreciated. I will be happy if you continue where you left, writing very useful guides.

    I have wondered how to utilize my Synology NAS to host Python. I`m looking forward to the next post.

    If I may wish for more, I would love to see a Python set up including Flask.

    Like

    1. I will! I want to do flask too, but I haven’t figured it out yet and I am locked with other projects, but as soon as I crack it, I will post about it.
      Next post I will show how to schedule the scripts and then how to post to a website without flask. Soooo cool 🙂

      Like

  2. Awesome guide! much appreciate it 🙂
    Question though. If I already have a venv from Pycharm saved locally on the Synology, is it possible to simply index that venv and run it for a scheduled task?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.