使用 pip 和 pip3 安装软件包时会引发错误

使用 pip 和 pip3 安装软件包时会引发错误

我需要为脚本安装 python 库 scp 和 setuptools,但是当我尝试使用 pip 或 pip3 下载任何包时都会引发此错误。

ubuntu@ubuntu:~/testcommander/tests$ sudo pip3 install --upgrade --proxy=http://proxy.cat.com:80 setuptools The directory '/home/ubuntu/.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 '/home/ubuntu/.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. Exception: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 342, in run requirement_set.prepare_files(finder) File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 380, in prepare_files ignore_dependencies=self.ignore_dependencies)) File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 487, in _prepare_file req_to_install, finder) File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 428, in _check_skip_installed req_to_install, upgrade_allowed) File "/usr/lib/python3/dist-packages/pip/index.py", line 465, in find_requirement all_candidates = self.find_all_candidates(req.name) File "/usr/lib/python3/dist-packages/pip/index.py", line 423, in find_all_candidates for page in self._get_pages(url_locations, project_name): File "/usr/lib/python3/dist-packages/pip/index.py", line 568, in _get_pages page = self._get_page(location) File "/usr/lib/python3/dist-packages/pip/index.py", line 683, in _get_page return HTMLPage.get_page(link, session=self.session) File "/usr/lib/python3/dist-packages/pip/index.py", line 792, in get_page "Cache-Control": "max-age=600", File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/sessions.py", line 521, in get return self.request('GET', url, **kwargs) File "/usr/lib/python3/dist-packages/pip/download.py", line 386, in request return super(PipSession, self).request(method, url, *args, **kwargs) File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/sessions.py", line 508, in request resp = self.send(prep, **send_kwargs) File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/sessions.py", line 618, in send r = adapter.send(request, **kwargs) File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/adapter.py", line 47, in send resp = super(CacheControlAdapter, self).send(request, **kw) File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/adapters.py", line 405, in send conn = self.get_connection(request.url, proxies) File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/adapters.py", line 303, in get_connection proxy_manager = self.proxy_manager_for(proxy) File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/adapters.py", line 197, in proxy_manager_for **proxy_kwargs) File "/usr/share/python-wheels/urllib3-1.22-py2.py3-none-any.whl/urllib3/poolmanager.py", line 440, in proxy_from_url return ProxyManager(proxy_url=url, **kw) File "/usr/share/python-wheels/urllib3-1.22-py2.py3-none-any.whl/urllib3/poolmanager.py", line 385, in __init__ proxy = parse_url(proxy_url) File "/usr/share/python-wheels/urllib3-1.22-py2.py3-none-any.whl/urllib3/util/url.py", line 199, in parse_url raise LocationParseError(url) urllib3.exceptions.LocationParseError: Failed to parse: proxy.cat.com:80

答案1

你尝试过这个吗?

目录 '/home/ubuntu/.cache/pip/http' 或其父目录不属于当前用户,并且缓存已被禁用。请检查该目录的权限和所有者。如果使用 sudo 执行 pip,您可能需要 sudo 的 -H 标志。目录 '/home/ubuntu/.cache/pip' 或其父目录不属于当前用户,并且缓存轮已被禁用。请检查该目录的权限和所有者。如果使用 sudo 执行 pip,您可能需要 sudo 的 -H 标志。

相关内容