Installing pip on a DSM/Synology
Asked Answered
M

5

16

I've been working on a program using python 3 for the last few months. I've been testing it for some time now and it seems to work as it should. So I've tried to get it up and running on a DSM/Synology(Model: DS209+, Version: DSM 4.2-3259). Sadly I don't know anything about this environment. So I installed python3 (3.3.2-0005) from the Synology Package Center and got it working. Running my code works. The only problem is, that my program uses the "requests" library. However I just can't get pip running. For installing pip, I tried to use the following line in PuTTY.

curl -k https://bootstrap.pypa.io/get-pip.py | python3

I'd expect pip to download/install and use it to get the requests library. But then this happens and I have don't know what I did wrong:

The directory '/var/services/homes/admin/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/var/services/homes/admin/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 131kB/s
Collecting setuptools
  Downloading setuptools-38.2.4-py2.py3-none-any.whl (489kB)
    100% |################################| 491kB 305kB/s
Collecting wheel
  Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB)
    100% |################################| 51kB 296kB/s
Installing collected packages: pip, setuptools, wheel
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.3/distutils/sysconfig.py", line 449, in _init_posix
    with open(filename) as file:
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/include/python3.3m/pyconfig.h'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/tmpdqp31o/pip.zip/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/tmp/tmpdqp31o/pip.zip/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/tmp/tmpdqp31o/pip.zip/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/tmp/tmpdqp31o/pip.zip/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/tmp/tmpdqp31o/pip.zip/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/tmp/tmpdqp31o/pip.zip/pip/wheel.py", line 247, in move_wheel_files
    prefix=prefix,
  File "/tmp/tmpdqp31o/pip.zip/pip/locations.py", line 153, in distutils_scheme
    i.finalize_options()
  File "/usr/local/lib/python3.3/distutils/command/install.py", line 313, in finalize_options
    (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
  File "/usr/local/lib/python3.3/distutils/sysconfig.py", line 531, in get_config_vars
    func()
  File "/usr/local/lib/python3.3/distutils/sysconfig.py", line 456, in _init_posix
    raise DistutilsPlatformError(my_msg)
distutils.errors.DistutilsPlatformError: invalid Python installation: unable to open /usr/local/include/python3.3m/pyconfig.h (No such file or directory)

It seems like using sudo -H would fix the issue. However I have no idea how to do that and where to start. Googling the issue didn't help much either because the things I found where either too vague for me to understand or they had this issue with pip already installed. I hope this question isn't too vague either.

Mopboard answered 5/12, 2017 at 9:17 Comment(2)
So your problem is you don't know how to change to sudo session? Login as admin, enter sudo -i in PuTTY terminal, enter admin password, then repeat the installation command.Luftwaffe
relevant: pip.pypa.io/en/stable/installing/#do-i-need-to-install-pipMenorrhagia
C
27

When using a new venv pip is available automatically. For example:

user@host:~$ python3 -m venv env
user@host:~$ . env/bin/activate
(env) user@host:~$ pip --version
pip 7.1.2 from /volume1/homes/user/env/lib/python3.5/site-packages (python 3.5)

After that you can upgrade pip to the current version:

user@host:~$ pip install --upgrade pip
...
Successfully installed pip-18.0

This also has the advantage that installing packages with pip cannot break the system python.

To automatically activate your environment you can create a .profile:

user@host:~$ touch ~/.profile
user@host:~$ chmod u=rwx ~/.profile

and then make the content of it look like this:

#!/bin/sh
. env/bin/activate
Crosson answered 10/8, 2018 at 21:27 Comment(4)
Error: Command '['/volume1/@fake_home_link/admin/env/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1. - virtual envs sometimes don't work on synology.Silkworm
@TomaszGandor Which Synology device and Python version are you using? I just checked, the current Python 3.9 still supports -m venv and the current pip 20.3.3 still supports Python 3.5, so I would have expected this to still work even on newer devices.Crosson
Python 3.8.2 (tags/Contacts-1.0.0-0232-200617:57e5f51, Jun 29 2020, 09:38:27) [GCC 4.9.3 20150311 (prerelease)] on linux, the device is DS218j with 6.2.2 in /etc/VERSION. The venv module is there, but NOT ensurepip. So I can get pip with https://bootstrap.pypa.io/get-pip.py, then python3 -m pip install virtualenv and use that, or go: python3 -m venv --without-pip env2 - and then it uses the "global" pip (which defeats the purpose of a venv).Silkworm
This method is nearly there. You can use venv and a non-global pip by reversing the order: python3 -m venv env --without-pip . env/bin/activate curl https://bootstrap.pypa.io/get-pip.py | python The final python is running in the context of your venv so it'll be your python3 from synopkg. The pip will go into ~/env/bin and ~/env/bin/python will point to python3 which will point to /usr/local/bin/python3.Wristband
A
17

Like @hoefling already mentioned, it's a privilege issue.

Login via SSH

ssh user@synology

and enter user password.

Get admin privileges

sudo su

and enter sudo password.

Get installation file

wget https://bootstrap.pypa.io/get-pip.py

and execute installation file.

python get-pip.py

Let me know if it worked for you.

Abaddon answered 14/12, 2017 at 10:16 Comment(5)
Thank you very much for your answer. Logging in via SSH works without any problems but when I tried to use sudo I got the following response: -sh: sudo: not found. So I looked up how to install sudo and I found that using ipkg should work. I installed ipkg but when I try to use it, I get the following error: ipkg_conf_init: Failed to create temporary directory '(null)': Permission deniedMopboard
Only the admin or a user with admin rights can install software. Make sure you do have admin rights. The easiest way to make sure about that is to use ssh admin@synonlogy. Then you should be able to enable sudo -i or sudo -su or whatever. Let me know if that worked for you!Abaddon
Please make sure you execute the .py with admin rights. For example with ‘sudo python get-pip.py’. Let me know if this worked for you! If not, please post the error message.Abaddon
Man, you have two versions of python installed. Use ‘sudo python2.7 get-pip.py’ and see if it works. If yes, read up on how to get rid of the old version. Depending on the OS it’s not very simple. Hit me up if you need help with that! When two versions are specified, opening python usually gets you to the version that has been there first. In your case to python2.7. Sorry I’m currently on mobile. :)Abaddon
Thank you for this answer, the scripts work perfectly until "python get-pip.py". The error is"ERROR: This script does not work on Python 2.7 The minimum supported Python version is 3.6." But in my synology, i installed the python3 app, and didn't install python2. I understand it maybe the default version, so what should i do to change to python3 now? anything like pyen in Synology?Welldone
C
6

Login to DSM with root permission via SSH/Telnet:

  • SSH to your Synology device using your admin account: ssh [email protected]
  • Run sudo -i to switch to root.

After successfully logging in as root, you will have the permissions needed to install pip:

root@x:~# curl -k https://bootstrap.pypa.io/get-pip.py | python3
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1558k  100 1558k    0     0  1076k      0  0:00:01  0:00:01 --:--:-- 1076k
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 506kB/s
Collecting setuptools
  Downloading setuptools-38.4.0-py2.py3-none-any.whl (489kB)
    100% |████████████████████████████████| 491kB 1.1MB/s
Collecting wheel
  Using cached wheel-0.30.0-py2.py3-none-any.whl
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-9.0.1 setuptools-38.4.0 wheel-0.30.0
Cardigan answered 27/1, 2018 at 13:34 Comment(2)
This worked for me, but at the end, I got the message that the scripts were placed in /volume1/@appstore/py3k/usr/local/bin/ and were not in my normal search path. For now, I symlinked them to /usr/local/bin.Berndt
The script wheel ends up in my /var/packages/py3k/target/usr/local/bin. why do you need to symlink to /usr/local/bin , and how to do it?Welldone
J
1

I installed pip following this method:

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

However, some libraries won't install as Synology's latest version of Python is by now 3.5. If this can be of some use for everyone, I used easy.install package found in @appstore/py3k/usr/local/bin to install pip packages; some of them (like telepot) won't install with pip for some aiohttp issues.

Jacobsen answered 24/3, 2020 at 14:8 Comment(0)
M
0

My synology box only has Python 3.4.1 available, very old box that I have not updated.

using get-pip.py does not work because that currently needs python 3.5 or greater. However, the following did work:

python3 -m ensurepip --default-pip

Manille answered 1/11, 2020 at 14:46 Comment(1)
I have a ds218j with Python 3.8. get-pip.py works, but ensurepip doesn't.Silkworm

© 2022 - 2024 — McMap. All rights reserved.