0%

在群辉上面安装pip

说明

关于NAS,群辉肯定是不得不提的,本人之前也是疫情在家的时候买了一个小猫盘,也算是尝鲜了一波NAS吧,毕竟猫盘的性能还是有点捉急的,而且是ARM的(以后肯定还是要装一台x86的)。然后最近稍微学习了一下Python的requests,正缺一个24小时不关机的设备跑Python的,如实就想到了群辉,而且也装好了Python,但是奈何没有pip,于是查询了一些资料(国内的几个方法好像都不行),终于给解决了。

群辉安装Python

这一点应该不用说了吧,直接去群辉的套件中心,一键安装即可,然后再用SSH登录,输入python -v或者python3 -v即可查看Python版本,并且进入对应的Python环境。

安装request库

看了一些资料,比如学海无涯的B站专栏,这个应该是讲的最详细的一个了,但是很无奈,我这边尝试了没用,不知道是不是我平台的问题。然后就有继续找,找到了stackoverrun上面的问题讨论,也是在讨论这个问题,下面给出了相应的答案,而且回答的十分详细,步骤真的超级简单,如实就尝试了一下,果然成功了!

  • 首先登陆SSH并输入密码

    1
    ssh user@synology
  • 获取管理员权限

    1
    sudo su
  • 下载脚本文件到本地

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

*最后运行文件即可

1
python get-pip.py

下面是我运行的结果(包括了最后输入pip的测试):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
ash-4.3# wget https://bootstrap.pypa.io/get-pip.py
--2020-10-23 08:43:55-- https://bootstrap.pypa.io/get-pip.py
Resolving bootstrap.pypa.io... 151.101.228.175, 2a04:4e42:36::175
Connecting to bootstrap.pypa.io|151.101.228.175|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1886796 (1.8M) [text/x-python]
Saving to: 'get-pip.py'

get-pip.py 100%[===========================================>] 1.80M 1.26MB/s in 1.4s

2020-10-23 08:43:58 (1.26 MB/s) - 'get-pip.py' saved [1886796/1886796]

ash-4.3# python get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting pip
Downloading pip-20.2.4-py2.py3-none-any.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 272 kB/s
Collecting setuptools
Downloading setuptools-44.1.1-py2.py3-none-any.whl (583 kB)
|████████████████████████████████| 583 kB 6.6 MB/s
Collecting wheel
Downloading wheel-0.35.1-py2.py3-none-any.whl (33 kB)
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-20.2.4 setuptools-44.1.1 wheel-0.35.1
ash-4.3# pip

Usage:
pip <command> [options]

Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
config Manage local and global configuration.
search Search PyPI for packages.
cache Inspect and manage pip's wheel cache.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
debug Show information useful for debugging.
help Show help for commands.

General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user
configuration.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be used up to 3 times
(corresponding to WARNING, ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--no-input Disable prompting for input.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup,
(a)bort.
--trusted-host <hostname> Mark this host or host:port pair as trusted, even though it does not have valid
or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private key and the
certificate in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine whether a new version of pip is
available for download. Implied with --no-index.
--no-color Suppress colored output
--no-python-version-warning
Silence deprecation warnings for upcoming unsupported Pythons.
--use-feature <feature> Enable new functionality, that may be backward incompatible.
--use-deprecated <feature> Enable deprecated functionality, that will be removed in the future.

下一步问题

到这里貌似已经完美解决了问题,但是我发现一个问题,我实用下列指令安装了一下requests

1
pip install requests

但是在实际的实用过程中,我是用的是Python3,具体版本是3.8.2,我import requests发现直接报错,经过一番查找,发现这里的pip居然是python2的,跟我在PC上面使用的体验全完不用,可能是他默认的版本是Python2,这个的话Linux一般都是默认的2而不是3,然后我又继续小找了一番,找到了码农家园的一个帖子,回复的超级乱,但是我还是找到了一些有用的信息,然后根据系统给出的提示,终于给弄好了,下面说说具体的步骤:

首先我直接删除之前下载的get-pip.py文件,然后重新下载了一个:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ash-4.3# ls
get-pip.py
ash-4.3# rm get-pip.py
ash-4.3# curl -O https://bootstrap.pypa.io/get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1842k 100 1842k 0 0 359k 0 0:00:05 0:00:05 --:--:-- 445k
ash-4.3# sudo python3 get-pip.py
Collecting pip
Using cached pip-20.2.4-py2.py3-none-any.whl (1.5 MB)
Collecting setuptools
Downloading setuptools-50.3.2-py3-none-any.whl (785 kB)
|████████████████████████████████| 785 kB 71 kB/s
Collecting wheel
Using cached wheel-0.35.1-py2.py3-none-any.whl (33 kB)
Installing collected packages: pip, setuptools, wheel
WARNING: The scripts pip, pip3 and pip3.8 are installed in '/var/packages/py3k/target/usr/local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts easy_install and easy_install-3.8 are installed in '/var/packages/py3k/target/usr/local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script wheel is installed in '/var/packages/py3k/target/usr/local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-20.2.4 setuptools-50.3.2 wheel-0.35.1

大家可以仔细看看这个里面的说明,目录是在 /var/packages/py3k/target/usr/local/bin 下面,这个时候pip3是不能用的:

1
2
ash-4.3# pip3
ash: pip3: command not found

然后我又进入到他给的文件夹里面,看看有什么东西,发现有pip3这个文件,真的超级开心有木有,然后尝试用了一下:

1
2
3
4
5
6
7
ash-4.3# cd /var/packages/py3k/target/usr/local/bin
ash-4.3# ls
easy_install easy_install-3.8 pip pip3 pip3.8 python3 python3.8 wheel
ash-4.3# pip3 install requests
ash: pip3: command not found
ash-4.3# pip3 -v
ash: pip3: command not found

哎,还是不能用,你别说,我又试了一下pip -v,默认的pip2还是能行,你说气不气?
然后我想了一下,既然不能直接运行,我用./command这种运行的方式还不行吗?得到一下结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
ash-4.3# ./pip3

Usage:
pip3 <command> [options]

Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
config Manage local and global configuration.
search Search PyPI for packages.
cache Inspect and manage pip's wheel cache.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
debug Show information useful for debugging.
help Show help for commands.

General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--no-input Disable prompting for input.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
--trusted-host <hostname> Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
--no-color Suppress colored output
--no-python-version-warning
Silence deprecation warnings for upcoming unsupported Pythons.
--use-feature <feature> Enable new functionality, that may be backward incompatible.
--use-deprecated <feature> Enable deprecated functionality, that will be removed in the future.

喜出望外,然后果断使用./pip install xxx安装了 requests 并且 import 了一下,发现可以用,真的是喜出望外,具体如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
ash-4.3# ./pip3 install requests
Collecting requests
Using cached requests-2.24.0-py2.py3-none-any.whl (61 kB)
Collecting certifi>=2017.4.17
Using cached certifi-2020.6.20-py2.py3-none-any.whl (156 kB)
Collecting chardet<4,>=3.0.2
Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting idna<3,>=2.5
Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
Using cached urllib3-1.25.11-py2.py3-none-any.whl (127 kB)
Installing collected packages: certifi, chardet, idna, urllib3, requests
WARNING: The script chardetect is installed in '/var/packages/py3k/target/usr/local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.10 requests-2.24.0 urllib3-1.25.11
ash-4.3# python3
Python 3.8.2 (tags/Contacts-1.0.0-0232-200617:57e5f51, Jun 29 2020, 09:38:52)
[GCC 4.9.4 20150629 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>

可以看到,import的时候没有报错,现在已经是可以正常使用了。但是距离完美使用肯定是差一点点的,可以看到我们不可能每次都进入到/var/packages/py3k/target/usr/local/bin这个目录来使用pip3指令的,因此最后一步当然是将该目录加入到PATH中啦,指令如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
ash-4.3# export PATH="/var/packages/py3k/target/usr/local/bin:$PATH"
ash-4.3# pip3

Usage:
pip3 <command> [options]

Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
config Manage local and global configuration.
search Search PyPI for packages.
cache Inspect and manage pip's wheel cache.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
debug Show information useful for debugging.
help Show help for commands.

General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--no-input Disable prompting for input.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
--trusted-host <hostname> Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
--no-color Suppress colored output
--no-python-version-warning
Silence deprecation warnings for upcoming unsupported Pythons.
--use-feature <feature> Enable new functionality, that may be backward incompatible.
--use-deprecated <feature> Enable deprecated functionality, that will be removed in the future.

上面添加了以后我还测试了一下,任何位置都可以使用pip3来安装相应的库,好用多了!

结尾

完美解决,皆大欢喜~

-------------本文结束感谢您的阅读-------------