gpt4 book ai didi

pip - 如何在 Ubuntu 14.04 上使用 python3.6 而不是 python3.4 调整 pip3?

转载 作者:行者123 更新时间:2023-12-01 19:38:01 24 4
gpt4 key购买 nike

Ubuntu 14.04 上的默认 python33.4.3,但我想使用 3.6.3

我按照以下命令安装3.6.3:

$ sudo apt-get update
$ sudo apt-get install build-essential libpq-dev libssl-dev openssl libffi-dev zlib1g-dev
$ sudo apt-get install python3-pip python3-dev

$ sudo add-apt-repository ppa:jonathonf/python-3.6
$ sudo apt-get update
$ sudo apt-get install python3.6

3.6.3 然后在我的 Ubuntu 上可用:

$ which python3.6
/usr/bin/python3.6

当然,python3 仍然指向 3.4.3:

$ ls -la /usr/bin/python3
/usr/bin/python3 -> /usr/bin/python3.4

pip3 可用,但它使用 3.4.3 而不是 3.6.3 (我想要的):

$ pip3 --version
pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.4)

我认为更新 /usr/bin/python3 可以解决问题,因此我调整了 python3 符号链接(symbolic link),使其指向 3.6.3:

$ sudo unlink /usr/bin/python3
$ sudo ln -s /usr/bin/python3.6 /usr/bin/python3
$ ls -la /usr/bin/python3
/usr/bin/python3 -> /usr/bin/python3.6

但是pip3不再工作了:(

$ pip3 --version
Traceback (most recent call last):
File "/usr/bin/pip3", line 5, in <module>
from pkg_resources import load_entry_point
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'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
File "/usr/bin/pip3", line 5, in <module>
from pkg_resources import load_entry_point
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'

已更新

我尝试了一些建议:

$ sudo python3.6 -m pip

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

但它显示了非常相似的输出:

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'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg

如何解决这个问题?

最佳答案

嗨,真正的问题描述如下:https://stackoverflow.com/a/41722610/7933710TLDR:在较旧的 Ubuntu 系统上使用 ppa 并不一致。

要修复您的系统,您必须删除 python3.6:

apt-get remove --purge python3.6
add-apt-repository -r ppa:jonathonf/python-3.6

然后下载源代码并从源代码构建并准备用于构建的系统:

wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz

现在准备构建系统:

apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev  libncursesw5-dev xz-utils tk-dev

所有这些步骤均来自此处的指南 https://realpython.com/installing-python/#compiling-python-from-source

现在配置、制作、制作 altinstall(重要)

tar xvf Python-3.6.7.tgz
cd Python-3.6.7/
./configure --enable-optimizations --with-ensurepip=install
make -j 8
make altinstall

The -j 8 means run on 8 cores. Of course if you have less then use the appropriate number. It will not cause a crash in any case.

现在通过运行验证安装

python3.6 -V
which python3.6

复制python3.6的路径,它应该是/usr/bin/python3.6/usr/local/bin/python3。 6

您现在可以使用update-alternatives来管理您计算机上的所有Python版本

ls /usr/bin/python*  # e.g. /usr/bin/python2.7 /usr/bin/python3.4 /usr/bin/python3.6
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1
update-alternatives --install /usr/bin/python python /usr/local/bin/python3.6 2

数字2表示在您的计算机上运行Python的优先级。在本例中 2 > 1,因此您会更喜欢 python3.6。如果您想更改为 3.4 版本,只需运行 update-alternatives --config python 这是一个交互式配置器。

现在您可以使用python -m pip -V来验证pip是否正常工作。您还可以使用pip3.6来安装软件包。

关于pip - 如何在 Ubuntu 14.04 上使用 python3.6 而不是 python3.4 调整 pip3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53407801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com