Jennings
Jennings

Reputation: 457

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

Background

My attempts to resolve the issue

I have a hard time interpreting the Traceback, but here it is below:

$ 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

Why is the version returned not a string or byte? Is there a bug in my python 3.6 package itself? I am thinking about opening up those files in the traceback to see if I can debug it, but I thought I should ask for help before attempting something that sounds a little ridiculous, imo.

Other things I have tried

Traceback (pip2):

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

Traceback (pip3): see the first Traceback

pip version and python site output

$ 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

Upvotes: 12

Views: 12610

Answers (3)

Jennings
Jennings

Reputation: 457

The true fix is just bite the bullet and use virtual environments to ensure packages work, whether that's using Anaconda-gui, conda, pipenv, poetry or venv directly (you should be able to google).

I was in a time crunch, and the answer below by Wʜᴀᴄᴋᴀᴍᴀᴅᴏᴏᴅʟᴇ3000 gave me the band-aid to complete what I needed to do. I'm going to leave it here for archival purposes.


Per ᴡʜᴀᴄᴋᴀᴍᴀᴅᴏᴏᴅʟᴇ3000 answer in the comments, which was deleted, this fixed it. If you are ᴡʜᴀᴄᴋᴀᴍᴀᴅᴏᴏᴅʟᴇ3000 and see this edit, feel free to make a comment and I can flag it as the 'accepted answer.' Per Greg Schmit's suggestion, I moved the answer to this section too. I'm new to stackexchange, so if you know how to contact ᴡʜᴀᴄᴋᴀᴍᴀᴅᴏᴏᴅʟᴇ3000, please do help. This is the answer for now unless someone can provide more insight. Not sure if this complication may be cygwin related or not.

  • Opened file "/usr/lib/python3.6/site-packages/packaging/version.py"

  • Changed the code on line 200 from match = self._regex.search(version) to match = self._regex.search(str(version))

  • Re-ran the code pip3 install jupyterlab

Now the python3 pandas module is recognized inside jupyterlab when I run import pandas as pd

Upvotes: 11

aketekt
aketekt

Reputation: 11

Adding sudo worked for me:

sudo pip3 install jupyterlab

Upvotes: 0

ThorSummoner
ThorSummoner

Reputation: 18079

I had some issue with existing *.egg-info files, removing those allowed pip to work again

Upvotes: 4

Related Questions