首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在DSM/Synology上安装pip

在DSM/Synology上安装pip
EN

Stack Overflow用户
提问于 2017-12-05 17:17:31
回答 5查看 32.9K关注 0票数 16

在过去的几个月里,我一直在开发一个使用python3的程序。我已经对它进行了一段时间的测试,它似乎可以正常工作。所以我试着在DSM /Synology(型号: DS209+,版本:DSM4.2-3259)上启动并运行它。遗憾的是,我对这个环境一无所知。因此,我从Synology Package Center安装了python3 (3.3.2-0005),并使其正常工作。运行我的代码是可行的。唯一的问题是,我的程序使用了“request”库。然而,我就是不能让pip运行。为了安装pip,我尝试在PuTTY中使用以下代码行。

代码语言:javascript
运行
复制
curl -k https://bootstrap.pypa.io/get-pip.py | python3

我希望pip下载/安装并使用它来获取请求库。但是后来发生了这样的事情,我不知道我做错了什么:

代码语言:javascript
运行
复制
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的这个问题。我希望这个问题也不要太含糊。

EN

回答 5

Stack Overflow用户

发布于 2018-08-11 05:27:40

当使用新的venv pip时,它会自动可用。例如:

代码语言:javascript
运行
复制
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升级到当前版本:

代码语言:javascript
运行
复制
user@host:~$ pip install --upgrade pip
...
Successfully installed pip-18.0

这也有一个好处,即使用pip安装包不会破坏系统python。

要自动激活您的环境,您可以创建.profile

代码语言:javascript
运行
复制
user@host:~$ touch ~/.profile
user@host:~$ chmod u=rwx ~/.profile

然后让它的内容看起来像这样:

代码语言:javascript
运行
复制
#!/bin/sh
. env/bin/activate
票数 19
EN

Stack Overflow用户

发布于 2017-12-14 18:16:30

就像@hoefling已经提到的,这是一个特权问题。

通过SSH登录

代码语言:javascript
运行
复制
ssh user@synology

并输入用户密码。

获取管理员权限

代码语言:javascript
运行
复制
sudo su

然后输入sudo密码。

获取安装文件

代码语言:javascript
运行
复制
wget https://bootstrap.pypa.io/get-pip.py

并执行安装文件。

代码语言:javascript
运行
复制
python get-pip.py

让我知道它是否对你有效。

票数 16
EN

Stack Overflow用户

发布于 2018-01-27 21:34:47

Login to DSM with root permission via SSH/Telnet

使用您的管理员帐户:ssh admin@synology.fqdn.example.net

  • Run sudo -i切换到根目录。

以超级用户身份成功登录后,您将拥有安装pip所需的权限

代码语言:javascript
运行
复制
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
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47649902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档