过去几个月我一直在使用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这个问题。 我希望这个问题也不是太模糊。
答案 0 :(得分:7)
就像已经提到的@hoefling一样,这是一个特权问题。
通过SSH登录
ssh user@synology
并输入用户密码。
获取管理员权限
sudo su
输入sudo密码。
获取安装文件
wget https://bootstrap.pypa.io/get-pip.py
并执行安装文件。
python get-pip.py
让我知道它是否适合你。
答案 1 :(得分:6)
使用新的venv点时会自动可用。例如:
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
答案 2 :(得分:2)
Login to DSM with root permission via SSH/Telnet:
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
答案 3 :(得分:0)
我按照以下方法安装了pip:
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
但是,由于Synology的最新Python版本是3.5,因此无法安装某些库。
如果这对每个人都有用,我使用了easy.install
中的@appstore/py3k/usr/local/bin
软件包来安装pip软件包;其中一些(例如Telepot)将不会因某些aiohttp问题而与pip一起安装。
答案 4 :(得分:0)
我的synology框只有Python 3.4.1可用,非常老的框我还没有更新。
使用get-pip.py不起作用,因为当前需要python 3.5或更高版本。但是,以下方法确实有效:
python3 -m surepip --default-pip