背景

  • 我正尝试使用pip3 install jupyterlab安装Jupyter Lab,并且抛出了相同的错误。
  • 我没有弄清楚。使用pip2 install jupyterlab找到了一种解决方法-可以解决,但显然是一个临时的解决方法。
  • 尝试在python3笔记本(在jupyter实验室内部)中运行import pandas as pd;找不到模块。
  • 我正在使用Cygwin作为PC上的linux模拟器。
  • 我更喜欢python3.x,而不是python 2.7。

  • 我尝试解决的问题
  • 类似的报道来自JupyterLab的帖子-我在这里找到了此帖:Import pandas on jupyter ipython notebook fails,但是我相信作者使用的是 python (我不是),并且Type Error不同。
  • 我找到了与我的TypeError相关的帖子,但这是他正在编写的代码:Getting a TypeError: expected string or bytes-like object

  • 我很难解释Traceback,但是在下面是:
    $ 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软件包本身中有bug吗?我正在考虑在回溯中打开这些文件以查看是否可以调试它,但是我认为在尝试听起来有些可笑的imo之前,应该寻求帮助。

    我尝试过的其他东西
  • pip2 install --upgrade pip-这将返回一条消息,指出python2.7中的pip是最新的。

  • 追溯(pip2):
    $ pip2 install --upgrade pip
    Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages
    
  • pip3 install --upgrade pip-这在
  • 之上返回相同的TypeError

    追溯(pip3):请参阅第一个追溯

    pip版本和python网站输出
    $ 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
    

    最佳答案

    真正的解决方法就是硬着头皮,使用虚拟环境来确保程序包正常运行,无论是使用Anaconda还是直接通过命令行。

    我当时正处于时间紧缩的状态,下面3000英镑的答案给了我创可贴以完成我需要做的事情。我将其留在这里用于存档。

    注释中每ᴡʜᴀᴄᴋᴀᴍᴀᴅᴏᴏᴅʟᴇ3000的答案已被删除,此问题已得到解决。如果您的年龄是3000英镑,并且看到了此修改,请随时发表评论,我可以将其标记为“已接受的答案”。根据格雷格·施密特(Greg Schmit)的建议,我也将答案移到了本节。我是stackexchange的新手,所以如果您知道如何联系ᴡʜᴀᴄᴋᴀᴍᴀᴅᴏᴏᴅʟᴇ3000,请提供帮助。除非有人可以提供更多的见解,否则这是目前的答案。不知道这种并发症是否可能与cygwin有关。

  • 打开的文件“/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时,在jupyterlab中可以识别python3 pandas模块

    关于python - 在pip3中安装jupyterlab会抛出 'TypeError: expected string or bytes-like object',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49060525/

    10-13 08:48