Hướng dẫn ubuntu default python version - phiên bản python mặc định của Ubuntu

Tôi đã cố gắng đặt phiên bản Python mặc định thành

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
0 trong
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
1. Theo mặc định, đó là
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
2 (2.7). Tôi đã làm theo các bước dưới đây:
update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3

Nhưng tôi đang gặp lỗi sau cho câu lệnh thứ hai,

[email protected]:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs    

Use 'update-alternatives --help' for program usage information.   

Siêu bão

4.7465 Huy hiệu vàng20 Huy hiệu bạc32 Huy hiệu Đồng5 gold badges20 silver badges32 bronze badges5 gold badges20 silver badges32 bronze badges

Đã hỏi ngày 1 tháng 2 năm 2017 lúc 17:57Feb 1, 2017 at 17:57Feb 1, 2017 at 17:57

RejeeshchandranrejeeshchandranRejeeshChandranRejeeshChandran

3.9983 Huy hiệu vàng23 Huy hiệu bạc32 Huy hiệu Đồng3 gold badges23 silver badges32 bronze badges3 gold badges23 silver badges32 bronze badges

8

Dòng thứ hai được đề cập có thể được thay đổi thành

[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10

Điều này ưu tiên 10 cho con đường

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
0.

Nhược điểm của việc chỉnh sửa thay thế

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
4 là sử dụng các lệnh có
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
5 sẽ không hoạt động.

Nico Schlömer

48.8K24 Huy hiệu vàng186 Huy hiệu bạc223 Huy hiệu Đồng24 gold badges186 silver badges223 bronze badges24 gold badges186 silver badges223 bronze badges

Đã trả lời ngày 14 tháng 5 năm 2018 lúc 13:10May 14, 2018 at 13:10May 14, 2018 at 13:10

10

EDIT:

Tôi đã viết điều này khi tôi còn trẻ và ngây thơ,

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
6 là cách tốt hơn để làm điều này. Xem câu trả lời của @Pardhu.

Câu trả lời lỗi thời:

Mở tệp .bashrc của bạn

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
7. Nhập
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
8 vào một dòng mới ở đầu tệp sau đó lưu tệp bằng ctrl+o và đóng tệp bằng ctrl+x. Sau đó, trở lại tại dòng lệnh của bạn loại
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
9. Bây giờ bí danh của bạn nên là vĩnh viễn.

Nico Schlömer

48.8K24 Huy hiệu vàng186 Huy hiệu bạc223 Huy hiệu Đồng24 gold badges186 silver badges223 bronze badges24 gold badges186 silver badges223 bronze badges

Đã trả lời ngày 14 tháng 5 năm 2018 lúc 13:10May 14, 2018 at 13:10Feb 1, 2017 at 18:17

Tôi đã viết điều này khi tôi còn trẻ và ngây thơ,

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
6 là cách tốt hơn để làm điều này. Xem câu trả lời của @Pardhu.Steampunkery

Câu trả lời lỗi thời:2 gold badges19 silver badges28 bronze badges

8

Mở tệp .bashrc của bạn

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
7. Nhập
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
8 vào một dòng mới ở đầu tệp sau đó lưu tệp bằng ctrl+o và đóng tệp bằng ctrl+x. Sau đó, trở lại tại dòng lệnh của bạn loại
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
9. Bây giờ bí danh của bạn nên là vĩnh viễn.

Đã trả lời ngày 14 tháng 5 năm 2018 lúc 13:10Feb 1, 2017 at 18:17

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
6 là cách tốt hơn để làm điều này. Xem câu trả lời của @Pardhu.Steampunkery

  1. Câu trả lời lỗi thời:2 gold badges19 silver badges28 bronze badges

    Đã trả lời ngày 1 tháng 2 năm 2017 lúc 18:17
  2. SteamPunkeryStebunkery

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
  1. 3,8112 huy hiệu vàng19 Huy hiệu bạc28 Huy hiệu đồng

    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
    
    7 0

  2. Để thay đổi Python 3.6.8 như mặc định trong Ubuntu 18.04 thành Python 3.7.

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
7

Cài đặt Python 3.7

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
6

Các bước để cài đặt Python3.7 và định cấu hình nó làm trình thông dịch mặc định.3 gold badges20 silver badges34 bronze badges

Cài đặt gói Python3.7 bằng apt-getAug 24, 2019 at 23:03

5

Thêm Python3.6 & Python 3.7 vào

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
2

Cập nhật Python 3 để chỉ vào Python 3.73 gold badges20 silver badges34 bronze badges

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
72 Nhập 2 cho Python 3.7Aug 24, 2019 at 23:03May 18, 2020 at 20:12

Kiểm tra phiên bản Pythonsilviot

Alvin Sartor

1.9673 huy hiệu vàng20 Huy hiệu bạc34 Huy hiệu đồngMay 18, 2020 at 20:124 gold badges37 silver badges50 bronze badges

3

Đã trả lời ngày 24 tháng 8 năm 2019 lúc 23:03silviot

Nếu bạn có Ubuntu 20.04 lts (Focal Fossa), bạn có thể cài đặt

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
73:4 gold badges37 silver badges50 bronze badgesFeb 1, 2017 at 18:00

trong đó thay thế cho Symlink trong DanteVoronoi

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
74 để trỏ đến
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
75.1 gold badge12 silver badges20 bronze badges

2

Đã trả lời ngày 18 tháng 5 năm 2020 lúc 20:12Feb 1, 2017 at 18:00

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
8.

SilviotsilviotDanteVoronoi

4.3954 Huy hiệu vàng37 Huy hiệu bạc 50 Huy hiệu Đồng1 gold badge12 silver badges20 bronze badges

Để thay đổi thành Python3, bạn có thể sử dụng lệnh sau trong thiết bị đầu cuối

Đã trả lời ngày 1 tháng 2 năm 2017 lúc 18:00

Dantevoronoidantevoronoi

example:

1.0731 Huy hiệu vàng12 Huy hiệu bạc20 Huy hiệu Đồng

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
77

Một cách an toàn đơn giản sẽ là sử dụng bí danh. Đặt cái này vào tệp ~/.bashrc: Nếu bạn đã sử dụng Gedit Editor

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
78

gedit ~/.bashrc

1.0731 Huy hiệu vàng12 Huy hiệu bạc20 Huy hiệu Đồng

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
78

Một cách an toàn đơn giản sẽ là sử dụng bí danh. Đặt cái này vào tệp ~/.bashrc: Nếu bạn đã sử dụng Gedit EditorFeb 9, 2018 at 10:32

gedit ~/.bashrcKhan

Để đi vào tệp BASHRC và sau đó ở đầu tệp BASHRC sẽ thay đổi sau.10 silver badges11 bronze badges

0

bí danh python = python3
Since Ubuntu 20.04, the python3 is the default version, but still, python is not registered as python3 by default. In order to make that happen, you can simply do :

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
2

Sau khi thêm các điều trên trong tệp. Chạy lệnh bên dưới
Old way:

bí danh python = python3Feb 9, 2018 at 10:32

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
1

Sau khi thêm các điều trên trong tệp. Chạy lệnh bên dướiKhan

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
2

nguồn ~/.bash_aliases hoặc nguồn ~/.bashrc10 silver badges11 bronze badges

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
3

$ Python --Version Since Ubuntu 20.04, the python3 is the default version, but still, python is not registered as python3 by default. In order to make that happen, you can simply do :
You should be fine now! Link

$ python3 --VersionOld way:Sep 15, 2017 at 18:34

$ bí danh Python = Python3Hossein

Đã trả lời ngày 9 tháng 2 năm 2018 lúc 10:3232 gold badges117 silver badges210 bronze badges

1

Khankhan

  • 1.19410 Huy hiệu bạc11 Huy hiệu đồng You should be fine now! Link
  • CẬP NHẬT: Kể từ khi Ubuntu 20.04, Python3 là phiên bản mặc định, nhưng vẫn vậy, Python không được đăng ký là Python3 theo mặc định. Để thực hiện điều đó, bạn có thể chỉ cần làm:Sep 15, 2017 at 18:34
  • Đã trả lời ngày 15 tháng 9 năm 2017 lúc 18:34
  • Hosseinhossein
  • 22.5K32 Huy hiệu vàng117 Huy hiệu bạc210 Huy hiệu đồng

Chỉ cần làm theo các bước này để giúp thay đổi Python mặc định thành phiên bản Python mới nâng cấp. Làm việc tốt cho tôi.Dec 30, 2019 at 9:19Dec 30, 2019 at 9:19

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
20 Cài đặt phiên bản Python mới nhất mà bạn muốn
[email protected]:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs    

Use 'update-alternatives --help' for program usage information.   
0
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
21 Nhập thư mục gốc nơi cài đặt Python
update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
2
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
22 hoặc
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
23. Hủy liên kết Python mặc định hiện tại
[email protected]:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs    

Use 'update-alternatives --help' for program usage information.   
2
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
24 Liên kết Phiên bản Python đã tải xuống mớiNov 25, 2019 at 18:32
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
25 Kiểm tra phiên bản Python mới và bạn tốt để điNov 25, 2019 at 18:32
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
25 Kiểm tra phiên bản Python mới và bạn tốt để đi

Đã trả lời ngày 30 tháng 12 năm 2019 lúc 9:19

Lúc đầu cài đặt Python3 và PIP3

Sau đó, trong cuộc chạy đầu cuối của bạn alias python='python3.6'
alias python='python3.6'

Kiểm tra phiên bản Python trong máy của bạn.Mar 28, 2018 at 14:28Mar 28, 2018 at 14:28

Đã trả lời ngày 25 tháng 11 năm 2019 lúc 18:32ParaicParaic

Để thêm thêm, bạn cũng có thể thêm bí danh cho PIP (trong .bashrc hoặc bash_aliases):1 silver badge6 bronze badges1 silver badge6 bronze badges

bí danh pip = 'pip3'

[email protected]:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs    

Use 'update-alternatives --help' for program usage information.   
3

Bạn nhiều người thấy rằng một bản cài đặt sạch của Python3 thực sự chỉ vào Python3.x để bạn có thể cần:

bí danh pip = 'pip3.6' bí danh python = 'python3.6'

Đã trả lời ngày 28 tháng 3 năm 2018 lúc 14:28Jan 15, 2021 at 14:18Jan 15, 2021 at 14:18

Paraicparaiccbcramcbcram

1371 Huy hiệu bạc6 Huy hiệu đồng2 silver badges5 bronze badges2 silver badges5 bronze badges

Đây là một cách đơn giản làm việc cho tôi.

Bạn có thể thay đổi

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
75 cho đường dẫn đến Python3 (hoặc phiên bản bạn muốn).

Nhưng hãy nhớ rằng

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
6 có lẽ là lựa chọn tốt nhất.

Đã trả lời ngày 15 tháng 1 năm 2021 lúc 14:18

Vì vậy, chỉ cần đặt một

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
2 3 hoặc một cái gì đó ở cuối

Đã trả lời ngày 1 tháng 2 năm 2017 lúc 19:30Feb 1, 2017 at 19:30Feb 1, 2017 at 19:30

Nhận con đường Python từ

[email protected]:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs    

Use 'update-alternatives --help' for program usage information.   
4

Sau đó đặt phiên bản Python của bạn

[email protected]:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs    

Use 'update-alternatives --help' for program usage information.   
5

Đã trả lời ngày 16 tháng 10 năm 2018 lúc 4:26Oct 16, 2018 at 4:26Oct 16, 2018 at 4:26

Để thay đổi Python 3.6.8 như mặc định trong Ubuntu 18.04 từ Python 2.7, bạn có thể thử công cụ dòng lệnh

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
6.
[email protected]:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs    

Use 'update-alternatives --help' for program usage information.   
6

Nếu bạn gặp lỗi "Không có lựa chọn thay thế nào cho Python" thì hãy tự thiết lập một giải pháp thay thế bằng lệnh sau:

[email protected]:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs    

Use 'update-alternatives --help' for program usage information.   
7

Thay đổi đường dẫn

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
75 thành phiên bản Python mong muốn của bạn cho phù hợp.

Đối số cuối cùng được chỉ định là ưu tiên của nó, nếu không có lựa chọn thay thế thủ công nào được thực hiện thay thế với số ưu tiên cao nhất sẽ được đặt. Trong trường hợp của chúng tôi, chúng tôi đã đặt mức độ ưu tiên 2 cho

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
26 và kết quả là
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
26 được đặt làm phiên bản Python mặc định tự động bằng lệnh Cập nhật-Diễn hóa.

Chúng tôi có thể chuyển đổi bất cứ lúc nào giữa các phiên bản thay thế Python được liệt kê ở trên sử dụng lệnh bên dưới và nhập số lựa chọn:

[email protected]:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs    

Use 'update-alternatives --help' for program usage information.   
8

Đã trả lời ngày 27 tháng 6 năm 2020 lúc 12:24Jun 27, 2020 at 12:24Jun 27, 2020 at 12:24

Đối với một cách tiếp cận duy nhất không xâm lấn, người dùng hiện tại:

[email protected]:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs    

Use 'update-alternatives --help' for program usage information.   
9
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
20
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
29 sẽ sẵn sàng trong một vỏ mới.

Đã trả lời ngày 22 tháng 3 năm 2019 lúc 8:52Mar 22, 2019 at 8:52Mar 22, 2019 at 8:52

Tdihptdihptdihptdihp

2.2692 huy hiệu vàng21 Huy hiệu bạc40 Huy hiệu đồng2 gold badges21 silver badges40 bronze badges2 gold badges21 silver badges40 bronze badges

Chỉ cần xóa

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
10:
[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10
0

Và cài đặt

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
73:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
2

Nó sẽ tự động hóa quá trình chuyển sang Python3 mới. Tùy chọn bạn có thể thoát khỏi các gói còn lại sau:

[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10
2

Đã trả lời ngày 25 tháng 5 năm 2020 lúc 8:22May 25, 2020 at 8:22May 25, 2020 at 8:22

0

Đặt mức độ ưu tiên cho Python mặc định trong thiết bị đầu cuối Linux bằng cách thêm điều này:

[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10
3

Ở đây, chúng tôi đặt

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
0 để có ưu tiên 10 và
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
2 thành ưu tiên 1. Điều này sẽ làm cho
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
0 Python mặc định. Nếu bạn muốn python2 làm mặc định thì hãy ưu tiên python2 cao hơn thì python3

Đã trả lời ngày 6 tháng 11 năm 2020 lúc 4:52Nov 6, 2020 at 4:52Nov 6, 2020 at 4:52

[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10
4

Đã trả lời ngày 1 tháng 10 năm 2021 lúc 9:11Oct 1, 2021 at 9:11Oct 1, 2021 at 9:11

1

[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10
5

Đã trả lời ngày 3 tháng 1 lúc 3:46Jan 3 at 3:46Jan 3 at 3:46

devpdevpdevpdevp

2.0542 Huy hiệu vàng13 Huy hiệu bạc23 Huy hiệu đồng2 gold badges13 silver badges23 bronze badges2 gold badges13 silver badges23 bronze badges

Cách tốt nhất trong Ubuntu 18.04 sẽ hoạt động cho tất cả người dùng là

[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10
6

Lưu các thay đổi và khởi động lại.

Sau khi khởi động lại phiên bản Python 3 mà bạn có trong hệ thống cùng với Python 2.7 sẽ được coi là mặc định. Bạn có thể cụ thể hơn bằng cách nói những điều sau đây trong bí danh nếu bạn có nhiều phiên bản Python 3.

[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10
7

Đã trả lời ngày 22 tháng 3 năm 2019 lúc 10:12Mar 22, 2019 at 10:12Mar 22, 2019 at 10:12

Mian Asbat Ahmadmian Asbat AhmadMian Asbat AhmadMian Asbat Ahmad

3.02810 Huy hiệu vàng39 Huy hiệu bạc66 Huy hiệu Đồng10 gold badges39 silver badges66 bronze badges10 gold badges39 silver badges66 bronze badges

Bạn đã không bao gồm đối số ưu tiên

[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10
8

Bạn có thể thay thế 5 bằng bất kỳ ưu tiên nào bạn muốn. Một thay thế ưu tiên cao hơn được ưu tiên hơn mức ưu tiên thấp hơn.

Đã trả lời ngày 2 tháng 9 năm 2020 lúc 12:26Sep 2, 2020 at 12:26Sep 2, 2020 at 12:26

Nếu có khả năng sử dụng trực tiếp phiên bản Python cụ thể, tôi sẽ sử dụng nó so với giải pháp

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
6 và
update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
16.

Ex.

[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10
9
update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
17 thực hiện mô -đun cụ thể cho phiên bản Python cụ thể đó. Dòng đầu tiên sẽ cài đặt pytest cho phiên bản và người dùng cụ thể đó ở vị trí có thể
update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
18

Đã trả lời ngày 15 tháng 12 năm 2021 lúc 1:21Dec 15, 2021 at 1:21Dec 15, 2021 at 1:21

JanpojanpoJanPoJanPo

1551 Huy hiệu bạc7 Huy hiệu đồng1 silver badge7 bronze badges1 silver badge7 bronze badges

Trong trường hợp của tôi, nó đã xảy ra khi tôi chạy lệnh này trong thiết bị đầu cuối "bí danh python = python3" của tôi

Đã trả lời ngày 29 tháng 5 năm 2021 lúc 3:11May 29, 2021 at 3:11May 29, 2021 at 3:11

Lúc đầu, đảm bảo Python3 được cài đặt trên máy tính của bạn

Chuyển đến thiết bị đầu cuối của bạn và loại:

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
19 để đi đến thư mục nhà của bạn

Nếu bạn chưa thiết lập

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
20 của mình, hãy nhập
update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
21 để tạo .bash_profile của bạn.

Hoặc, nhập

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
22 để chỉnh sửa tệp.

Sao chép và lưu

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
8 trong .Bash_profile.

Đóng và mở lại thiết bị đầu cuối của bạn. Sau đó nhập lệnh sau để kiểm tra xem Python3 có phải là phiên bản mặc định của bạn không:Python3 is your default version now:Python3 is your default version now:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
25

Bạn sẽ thấy Python 3.x.y là phiên bản mặc định của bạn.python 3.x.y is your default version.python 3.x.y is your default version.

Cheers!

Đã trả lời ngày 21 tháng 9 năm 2019 lúc 19:13Sep 21, 2019 at 19:13Sep 21, 2019 at 19:13

1

Làm cách nào để thay đổi phiên bản python trong ubuntu?

Làm cách nào để thay đổi Python thành 3,7 trong Ubuntu ?...

Bước 1: Kiểm tra phiên bản hiện tại.$ python3

Bước 2: Cập nhật các gói Ubuntu.Cập nhật sudo apt-get ..

Bước 3: Cài đặt Python3 ..

Bước 4: Cập nhật Python 3 để chỉ vào Python 3.7 ..

Làm cách nào để chuyển sang Python 3.7 trong Linux?

Phiên bản hiện tại trong sử dụng là 3,5 ....

Bước 1: Kiểm tra phiên bản hiện tại.$ python3 --Version.....

Bước 2: Cập nhật các gói Ubuntu.Cập nhật sudo apt-get ..

Bước 3: Cài đặt Python3 ..

Bước 4: Cập nhật Python 3 để chỉ vào Python 3.7 ..

Làm cách nào để chuyển sang Python 3.7 trong Linux?

Phiên bản hiện tại trong sử dụng là 3,5 ....

Bước 1: Kiểm tra phiên bản hiện tại.$ python3 --Version.....

Cách chuyển phiên bản Python trong Ubuntu/Debian..

Tạo Symlink và nhóm cho Python 2.7.Terminal mở và chạy lệnh sau để tạo liên kết tượng trưng và ưu tiên 1 cho Python 2.7.....