如何强制offlineimap使用python2.7?

如何强制offlineimap使用python2.7?

我正在设置一台新计算机并安装了,offlineimap但当pip install --user offlineimap我尝试运行它时,我收到一系列错误,因为 Offlineimap 不支持 Python3:

https://github.com/OfflineIMAP/offlineimap/issues/472

我确实安装了 2.7 以及 3:

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

但即使我也不知道如何强制 Offlineimap 使用它。

https://stackoverflow.com/questions/10919569/install-a-module-using-pip-for-specific-python-version我卸载并尝试重新安装,指定 python 版本,但这以其自己的特殊方式令人窒息:

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

完整的 OfflineIMAP 错误:

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

Traceback:
  File "/home/amanda/.local/lib/python3.6/site-packages/offlineimap/accounts.py", line 283, in syncrunner
    self.__sync()
  File "/home/amanda/.local/lib/python3.6/site-packages/offlineimap/accounts.py", line 359, in __sync
    remoterepos.getfolders()
  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
    af=self.af,
  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))

答案1

安装的 Python 3 Offlineimap 优先于安装的 Python 2。

要删除 Python 3 版本,请执行以下操作:

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

在此之后,希望它现在应该获取 Python 2 版本。

已知问题

至于您使用的错误pip,是 Debian/Ubuntu 已知问题。

sudo apt-get install python-pip

或者

sudo easy_install pip

应该修复它;正如OP还指出的,删除Python 3离线地图包后,安装Python 2版本apt而不是pip使用:

sudo apt install offlineimap

答案2

清理pip*

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

应将其~/.local/bin/pip删除。

本地重新安装pip

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

安装你的包:

$ python2.7 ~/.local/bin/pip install --user offlineimap

相关内容