关于python:在pip3中安装jupyterlab抛出’TypeError:期望字符串或类字节对象’

Install jupyterlab in pip3 throws 'TypeError: expected string or bytes-like object'

背景

  • 我试图用pip3 install jupyterlab安装jupyter实验室,但它却犯了同样的错误。

  • 我没弄明白。找到了一个使用pip2 install jupyterlab的解决方案——它起作用了,但显然是一个创可贴的解决方案。

  • 尝试在python3笔记本(Jupyter实验室内)中运行import pandas as pd;未找到模块。

  • 我在PC上使用cygwin作为Linux仿真器。

  • 我喜欢python3.x而不是python 2.7。

我试图解决这个问题

  • 类似的Jupyterlab帖子——我在这里发现:Jupyteripython笔记本上的导入熊猫失败了,但我相信作者使用的是Python(我不是),并且类型错误是不同的。

  • 我找到了一篇与我的typeerror相关的文章,但这是他写的代码:获取typeerror:预期的字符串或类似于object的字节。

我很难解释回溯,但下面是:

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
$ pip install --upgrade pip
Exception:
Traceback (most recent call last):
  File"/usr/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File"/usr/lib/python3.6/site-packages/pip/commands/install.py", line 335, in run
    wb.build(autobuilding=True)
  File"/usr/lib/python3.6/site-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File"/usr/lib/python3.6/site-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File"/usr/lib/python3.6/site-packages/pip/req/req_set.py", line 487, in _prepare_file
    req_to_install, finder)
  File"/usr/lib/python3.6/site-packages/pip/req/req_set.py", line 428, in _check_skip_installed
    req_to_install, upgrade_allowed)
  File"/usr/lib/python3.6/site-packages/pip/index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File"/usr/lib/python3.6/site-packages/pip/index.py", line 427, in find_all_candidates
    self._package_versions(page.links, search)
  File"/usr/lib/python3.6/site-packages/pip/index.py", line 595, in _package_versions
    v = self._link_package_versions(link, search)
  File"/usr/lib/python3.6/site-packages/pip/index.py", line 667, in _link_package_versions
    support_this_python = check_requires_python(link.requires_python)
  File"/usr/lib/python3.6/site-packages/pip/utils/packaging.py", line 34, in check_requires_python
    return python_version in requires_python_specifier
  File"/usr/lib/python3.6/site-packages/packaging/specifiers.py", line 698, in __contains__
    return self.contains(item)
  File"/usr/lib/python3.6/site-packages/packaging/specifiers.py", line 703, in contains
    item = parse(item)
  File"/usr/lib/python3.6/site-packages/packaging/version.py", line 31, in parse
    return Version(version)
  File"/usr/lib/python3.6/site-packages/packaging/version.py", line 200, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object

为什么版本返回的不是字符串或字节?我的python 3.6包本身有缺陷吗?我正在考虑打开这些文件的追溯,看看我是否可以调试它,但我认为我应该寻求帮助之前,尝试一些听起来有点荒谬的事情,我说。

我试过的其他东西

  • pip2 install --upgrade pip-返回一条消息,说明python2.7中的pip是最新的。

回溯(pip2):

1
2
$ pip2 install --upgrade pip
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages

  • pip3 install --upgrade pip—返回上面相同的类型错误

回溯(pip3):见第一个回溯

pip版本和python站点输出

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
$ pip2 --version
pip 9.0.1 from /usr/lib/python2.7/site-packages (python 2.7)

$ python -m site
sys.path = [
    '/home/jennings/Documents/hpv/hpv_missed_clinics',
    '/usr/lib/python2.7/site-packages/logilab_common-1.3.0-py2.7.egg',
    '/usr/lib/python2.7/site-packages/six-1.9.0-py2.7.egg',
    '/usr/lib/python27.zip',
    '/usr/lib/python2.7',
    '/usr/lib/python2.7/plat-cygwin',
    '/usr/lib/python2.7/lib-tk',
    '/usr/lib/python2.7/lib-old',
    '/usr/lib/python2.7/lib-dynload',
    '/usr/lib/python2.7/site-packages',
    '/usr/lib/python2.7/site-packages/gtk-2.0',
    '/usr/lib/python2.7/site-packages/wx-3.0-gtk3',
]
USER_BASE: '/home/jennings/.local' (exists)
USER_SITE: '/home/jennings/.local/lib/python2.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: True

$ pip --version
pip 9.0.1 from /usr/lib/python3.6/site-packages (python 3.6)

$ python3 -m site
sys.path = [
    '
/home/jennings/Documents/hpv/hpv_missed_clinics',
    '
/usr/lib/python36.zip',
    '
/usr/lib/python3.6',
    '
/usr/lib/python3.6/lib-dynload',
    '
/usr/lib/python3.6/site-packages',
    '
/home/jennings/Documents/kaggle/SQL_scavenger/src/bq-helper',
    '
/usr/lib/python3.6/site-packages/linkgrammar',
]
USER_BASE: '
/home/jennings/.local' (exists)
USER_SITE: '
/home/jennings/.local/lib/python3.6/site-packages' (doesn't exist)
ENABLE_USER_SITE: True


真正的解决方法就是咬紧牙关,使用虚拟环境来确保软件包的工作,无论是使用水蟒还是直接通过命令行。

我当时正处于时间危机中,下面的答案是W???????????????????3000给了我创可贴来完成我需要做的事情。我要把它留在这里存档。

每????????????????????在评论中有3000个答案被删除,这就修正了它。如果你是???????????????????3000,看这篇编辑,请随意发表评论,我可以将其标记为"接受的答案"。根据格雷格·施密特的建议,我也将答案移到了本节。我刚接触StackExchange,所以如果你知道如何联系????????????????????3000,请帮忙。这是目前的答案,除非有人能提供更多的洞察力。不确定这种并发症是否与赛格温有关。

  • 打开文件"/usr/lib/python3.6/site packages/packaging/version.py"

  • 将第200行的代码从match = self._regex.search(version)改为match = self._regex.search(str(version))

  • 重新运行代码pip3 install jupyterlab

现在,当我运行import pandas as pd时,python3熊猫模块在jupyterlab中被识别。