在服务器上安装/更新程序

在服务器上安装/更新程序

我正在通过 SSH 访问由 JustHost 托管的服务器,以便安装 Selenium 来进行一些网络抓取。

然而,我在尝试安装它时遇到了一个问题。

根据错误代码判断,我认为我需要更改特定目录的权限,尽管由于我购买了共享主机,我的权限受到限制,所以我想知道:

  1. 这是否确实是权限问题?
  2. 如果是的话,我应该将权限更改为什么?
  3. 最后,有没有什么办法可以解决权限受限的问题?

尝试安装 Selenium

日志

[email protected] [~]# pip install selenium You are using pip version 7.1.0, however version 10.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting selenium Using cached https://files.pythonhosted.org/packages/57/bc/17164fd471ccdf0df3a992c710c0c3c47743462ff41ab72a02c6ede96e90/selenium-3.12.0-py2.py3-none-any.whl Installing collected packages: selenium Exception: Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/pip/basecommand.py", line 223, in main status = self.run(options, args) File "/usr/lib/python2.6/site-packages/pip/commands/install.py", line 308, in run strip_file_prefix=options.strip_file_prefix, File "/usr/lib/python2.6/site-packages/pip/req/req_set.py", line 646, in install **kwargs File "/usr/lib/python2.6/site-packages/pip/req/req_install.py", line 816, in install strip_file_prefix=strip_file_prefix File "/usr/lib/python2.6/site-packages/pip/req/req_install.py", line 1013, in move_wheel_files strip_file_prefix=strip_file_prefix, File "/usr/lib/python2.6/site-packages/pip/wheel.py", line 339, in move_wheel_files clobber(source, lib_dir, True) File "/usr/lib/python2.6/site-packages/pip/wheel.py", line 310, in clobber ensure_dir(destdir) File "/usr/lib/python2.6/site-packages/pip/utils/__init__.py", line 70, in ensure_dir os.makedirs(path) File "/usr/lib64/python2.6/os.py", line 157, in makedirs mkdir(name, mode) OSError: [Errno 30] Read-only file system: '/usr/lib/python2.6/site-packages/selenium'

权限

[电子邮件保护][/usr/lib/python2.6/site-packages]# ls -l selenium /bin/ls: 无法访问 selenium:没有此文件或目录

因此显然目录(和包?)丢失了。

当我去更新 pip 时,我收到完全相同的错误。

错误

OSError: [Errno 30] Read-only file system: '/usr/bin/pip'

权限

[email protected] [/usr]# ls -l /usr/bin/pip -rwxr-xr-x 1 root root 281 Jul 1 2015 /usr/bin/pip*

因此我尝试通过以下方式安装 Selenium pip install --user selenium,控制台记录的内容如下:

Collecting selenium
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Using cached https://files.pythonhosted.org/packages/57/bc/17164fd471ccdf0df3a992c710c0c3c47743462ff41ab72a02c6ede96e90/selenium-3.12.0-py2.py3-none-any.whl
Installing collected packages: selenium
Successfully installed selenium

会不会InsecurePlatformWarning对后续运营造成影响?

答案1

这肯定是一个权限问题,您无法在没有 root 访问权限的情况下自行更改 root 拥有的目录的权限。不过,您可以采取一些措施来安装没有 root 访问权限的 Selenium:

您可以尝试pip使用--user标志运行,它将把包安装在您的主目录中,而不是/usr/lib/python2.6这是默认设置。因此:

pip install --user selenium

或者,你也可以从以下地址下载源代码发行版皮皮(如果您对最新的 Selenium 版本满意),解压目录,cd进入其中,然后运行:

python setup.py install

后一个命令不需要 root 访问权限即可完成安装。


编辑:现在您已经使用第一个提供的选项安装了 Selenium 并遇到了该错误,我将对其进行一些分解。

此错误与您选择的特定安装方法没有直接关系。本质上,这是有关您的 Python 版本的一般消息。旧版本的 Python 2 缺少SNI 支持其 SSL 模块中存在漏洞,总体安全性较差。理想情况下,您应咨询本指南介绍 urllib3并尝试解决您遇到的错误可能无需访问权限。

如果您想跳过所有这些步骤,您可以尝试切换到 Python 3(如果适合您)。运行 检查该机器上是否有 Python 3。python --version您需要使用python3pip3命令重复安装步骤。即python3 setup.py install

相关内容