I'm setting up a new computer and installed offlineimap with pip install --user offlineimap but when I try to run it I'm getting a series of errors because offlineimap doesn't support Python3:


I do have 2.7 installed as well as 3:

amanda@host:~$ python --version
Python 2.7.15rc1

but even I'm not sure how to force offlineimap to use it.

Per https://stackoverflow.com/questions/10919569/install-a-module-using-pip-for-specific-python-version I uninstalled and tried to reinstall, specifying the python version, but that's choking in its own special way:

amanda@host:~$ python2.7 ~/.local/bin/pip install --user offlineimap
Traceback (most recent call last):
  File "/home/amanda/.local/bin/pip", line 7, in <module>
    from pip._internal import main
ImportError: No module named pip._internal

The full OfflineIMAP error:

OfflineIMAP 7.2.1
  Licensed under the GNU GPL v2 or any later version (with an OpenSSL exception)
imaplib2 v2.57 (bundled), Python v3.6.5, OpenSSL 1.1.0g  2 Nov 2017
Account sync Example:
 *** Processing account Example
 Establishing connection to mail.example.info:993 (VelRemote)
 ERROR: While attempting to sync account 'Example'
  IMAP4 protocol error: program error: <class 'TypeError'> - cannot use a bytes pattern on a string-like object
 *** Finished account 'Example' in 0:00
ERROR: Exceptions occurred during the run!
ERROR: While attempting to sync account 'Example'
  IMAP4 protocol error: program error: <class 'TypeError'> - cannot use a bytes pattern on a string-like object

  File "/home/amanda/.local/lib/python3.6/site-packages/offlineimap/accounts.py", line 283, in syncrunner
  File "/home/amanda/.local/lib/python3.6/site-packages/offlineimap/accounts.py", line 359, in __sync
  File "/home/amanda/.local/lib/python3.6/site-packages/offlineimap/repository/IMAP.py", line 452, in getfolders
    imapobj = self.imapserver.acquireconnection()
  File "/home/amanda/.local/lib/python3.6/site-packages/offlineimap/imapserver.py", line 547, in acquireconnection
  File "/home/amanda/.local/lib/python3.6/site-packages/offlineimap/imaplibutil.py", line 194, in __init__
    super(WrappedIMAP4_SSL, self).__init__(*args, **kwargs)
  File "/home/amanda/.local/lib/python3.6/site-packages/offlineimap/bundled_imaplib2.py", line 2183, in __init__
    IMAP4.__init__(self, host, port, debug, debug_file, identifier, timeout, debug_buf_lvl)
  File "/home/amanda/.local/lib/python3.6/site-packages/offlineimap/bundled_imaplib2.py", line 400, in __init__
    self.welcome = self._request_push(name='welcome', tag='continuation').get_response('IMAP4 protocol error: %s')[1]
  File "/home/amanda/.local/lib/python3.6/site-packages/offlineimap/bundled_imaplib2.py", line 201, in get_response
    raise typ(exc_fmt % str(val))
  • Please add cat /home/amanda/.local/bin/pip.
    – GAD3R
    Jul 10, 2018 at 9:47

2 Answers 2


The installed Python 3 offlineimap is taking precedence over the installed Python 2.

For deleting the Python 3 version, do:

sudo rm -rf /home/amanda/.local/lib/python3.6/site-packages/offlineimap*

After this, hopefully it should now pickup the Python 2 version.

Known issue

As for your error using pip, is a Debian/Ubuntu known issue.

sudo apt-get install python-pip


sudo easy_install pip

should fix it; as the OP also stated, after deleting the Python 3 offlinemap package, the Python 2 version was installed with apt instead of pip with:

sudo apt install offlineimap
  • 1
    I didn't want to screw up the rest of my Python just for this so I tried just installing with sudo apt install offlineimap which worked fine. (I had already removed the offending Py3.6 package)
    – Amanda
    Jul 9, 2018 at 19:32
  • @Amanda correcting you pip wont screw up it. Eventually you will have to correct it, if it is not working correctly it will impact you in the short-medium term. Jul 9, 2018 at 23:48
  • Question: why would I use rm and not pip uninstall? The latter actually captures a few more files.
    – Amanda
    Jul 10, 2018 at 15:04
  • Ideally, pip would install 2.7 packages, while pip3 installs 3.6 packages. But pip isn't broken, it's just assuming I want to default to py3.
    – Amanda
    Jul 10, 2018 at 15:06
  • @Amanda The default is python 2. It is "broken" in a sense some configuration change it´s behaviour, and many apps and instructions expect it to handle python 2, as you have found out. Jul 11, 2018 at 7:23

Clean up pip*

$ python3 -m pip uninstall pip
$ python -m pip uninstall pip

The ~/.local/bin/pip should be removed.

Reinstall pip locally:

$ curl -LO https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py --user

Install your package:

$ python2.7 ~/.local/bin/pip install --user offlineimap
  • This assumed I don't want my default to be python3, though, right?
    – Amanda
    Jul 10, 2018 at 15:02
  • @Amanda Just it will reinstall pip.
    – GAD3R
    Jul 10, 2018 at 18:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .