在DSM / Synology上安装pip
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在DSM / Synology上安装pip相关的知识,希望对你有一定的参考价值。
在过去的几个月里,我一直在研究使用python 3的程序。我已经测试了一段时间了,它似乎应该工作。所以我试图在DSM / Synology上运行它(模型:DS209 +,版本:DSM 4.2-3259)。可悲的是,我对这个环境一无所知。所以我从Synology Package Center安装了python3(3.3.2-0005)并让它运行起来。运行我的代码工作。唯一的问题是,我的程序使用“请求”库。但是我只是不能让pip运行。为了安装pip,我尝试在PuTTY中使用以下行。
curl -k https://bootstrap.pypa.io/get-pip.py | python3
我希望pip能够下载/安装并使用它来获取请求库。但后来发生了这种情况,我不知道自己做错了什么:
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)
似乎使用sudo -H可以解决这个问题。但是我不知道该怎么做以及从哪里开始。谷歌搜索这个问题并没有多大帮助,因为我发现的事情要么让我理解太模糊,要么已经安装了pip这个问题。我希望这个问题也不是太模糊。
就像@hoefling已经提到的那样,这是一个特权问题。
通过SSH登录
ssh user@synology
并输入用户密码。
获得管理员权限
sudo su
并输入sudo密码。
获取安装文件
wget https://bootstrap.pypa.io/get-pip.py
并执行安装文件。
python get-pip.py
让我知道它是否适合你。
使用新的venv pip时可自动使用。例如:
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)
之后,您可以将pip升级到当前版本:
user@host:~$ pip install --upgrade pip
...
Successfully installed pip-18.0
这也有一个好处,即使用pip安装包不会破坏系统python。
要自动激活您的环境,您可以创建一个.profile
:
user@host:~$ touch ~/.profile
user@host:~$ chmod u=rwx ~/.profile
然后使其内容看起来像这样:
#!/bin/sh
. env/bin/activate
Login to DSM with root permission via SSH/Telnet:
- 使用您的管理员帐户通过SSH连接Synology设备:
ssh admin@synology.fqdn.example.net
- 运行
sudo -i
切换到root。
以root身份成功登录后,您将拥有安装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
以上是关于在DSM / Synology上安装pip的主要内容,如果未能解决你的问题,请参考以下文章
如何仅使用一个浏览器 (Firefox) 在远程网络上同时访问多个 NAS 的 Synology-DSM?