16
votes

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.

5
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.hoefling

5 Answers

19
votes

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
15
votes

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.

6
votes

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
1
votes

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.

0
votes

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