0%

Ubuntu pip系列问题

问题1:给pip进行换源

/home/xzt/目录下创建.pip/目录,然后再.pip/下创建pip.conf文件。

image-20220622163816955

文件中写入如下内容即可。

1
2
3
[global]
trusted-host = pypi.douban.com
index-url = http://pypi.douban.com/simple

问题2:使用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
ERROR: Exception:
Traceback (most recent call last):
File "/usr/local/python/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 188, in _main
status = self.run(options, args)
File "/usr/local/python/lib/python3.8/site-packages/pip/_internal/commands/uninstall.py", line 54, in run
session = self.get_default_session(options)
File "/usr/local/python/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 83, in get_default_session
self._session = self.enter_context(self._build_session(options))
File "/usr/local/python/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 93, in _build_session
session = PipSession(
File "/usr/local/python/lib/python3.8/site-packages/pip/_internal/network/session.py", line 249, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/local/python/lib/python3.8/site-packages/pip/_internal/network/session.py", line 132, in user_agent
zip(["name", "version", "id"], distro.linux_distribution()),
File "/usr/local/python/lib/python3.8/site-packages/pip/_vendor/distro.py", line 125, in linux_distribution
return _distro.linux_distribution(full_distribution_name)
File "/usr/local/python/lib/python3.8/site-packages/pip/_vendor/distro.py", line 681, in linux_distribution
self.version(),
File "/usr/local/python/lib/python3.8/site-packages/pip/_vendor/distro.py", line 741, in version
self.lsb_release_attr('release'),
File "/usr/local/python/lib/python3.8/site-packages/pip/_vendor/distro.py", line 903, in lsb_release_attr
return self._lsb_release_info.get(attribute, '')
File "/usr/local/python/lib/python3.8/site-packages/pip/_vendor/distro.py", line 556, in __get__
ret = obj.__dict__[self._fname] = self._f(obj)
File "/usr/local/python/lib/python3.8/site-packages/pip/_vendor/distro.py", line 1014, in _lsb_release_info
stdout = subprocess.check_output(cmd, stderr=devnull)
File "/usr/local/python/lib/python3.8/subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/local/python/lib/python3.8/subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.

2-1

解决办法

  • 找到lsb_release.py模块所在的目录
1
sudo find / -name 'lsb_release.py'
  • 将其复制到设置python3.6的系统模块加载位置,也就是报错处subprocess.py所在的目录
1
sudo cp  /usr/lib/python3/dist-packages/lsb_release.py /usr/local/python3/lib/python3.6/

2-2

问题3:使用pip安装matplotlib报错

1
Command "/usr/local/python3/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-x0_i3ps6/pillow/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-7_n87fln/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-x0_i3ps6/pillow/

1

解决办法

先执行如下命令再进行安装

1
2
3
sudo apt-get install libjpeg-dev zlib1g-dev

pip3 install matplotlib --user

2

正在加载今日诗词....