如何在 Ubuntu 14.04 上将 pip 与 Python 3.6 结合使用?

如何在 Ubuntu 14.04 上将 pip 与 Python 3.6 结合使用?

我正在尝试按照以下说明安装 Python 3.6这个答案,但我似乎遇到了麻烦。我的系统如下(在 c9.io 上):

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:        14.04
Codename:       trusty

当我按照答案中的说明(添加 deadsnakes 存储库,,apt-get update)时sudo apt-get install python3.6,它似乎起作用了,即我可以运行命令python3.6并且解释器启动。

但是,当我尝试从其中使用 pip 时python3.6 -m pip --version,出现以下错误:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 59, in <module>
    from pip.log import logger
  File "/usr/lib/python3/dist-packages/pip/log.py", line 9, in <module>
    import colorama, pkg_resources
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/usr/share/python-wheels/setuptools-3.3-py2.py3-none-any.whl/pkg_resources.py", line 1479, in <module>
    register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

谷歌搜索了一下,我得到了这个所以回答。但是,当我运行命令时:

sudo pip3 install --upgrade pip

我现在遇到以下问题:

Requirement already up-to-date: pip in /usr/local/lib/python3.4/dist-packages (18.0)

卸载并再次安装 python3.6 也无济于事。尝试运行 pip 时仍然出现相同的错误。我该如何修复此问题?

编辑对重复的回应:

所谓重复的答案似乎对我不起作用。我运行了以下命令:

$ curl https://bootstrap.pypa.io/get-pip.py | sudo python3.6

从那里我得到了这个结果:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1604k  100 1604k    0     0  4637k      0 --:--:-- --:--:-- --:--:-- 4649k
Traceback (most recent call last):
  File "<stdin>", line 20651, in <module>
  File "<stdin>", line 197, in main
  File "<stdin>", line 119, in bootstrap
  File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 12, in <module>
    from setuptools.extension import Extension
  File "/usr/lib/python3/dist-packages/setuptools/extension.py", line 7, in <module>
    from setuptools.dist import _get_unpatched
  File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 16, in <module>
    import pkg_resources
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 1479, in <module>
    register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

请记住,我是在一个全新的环境中完成此操作的(即我首先安装了 python,然后运行 ​​get-pip.py)。

我应该怎么办?

相关内容