Các cuộc nói chuyện sau đây về việc nâng cấp từ 3.6.7 lên 3.7.0 nhưng bạn có thể sử dụng cùng một quy trình để hạ cấp. Bạn không nên thay đổi hệ thống Python trừ khi bạn thực sự biết những gì bạn đang làm
Cài đặt Pyenv đầu tiên
Hướng dẫn cài đặt ở đây
Nhìn vào các tùy chọn Pyenv
$ pyenv
pyenv 1.2.14
Usage: pyenv []
Some useful pyenv commands are:
commands List all available pyenv commands
activate Activate virtual environment
commands List all available pyenv commands
deactivate Deactivate virtual environment
doctor Verify pyenv installation and deevlopment tools to build pythons.
exec Run an executable with the selected Python version
global Set or show the global Python version
help Display help for a command
hooks List hook scripts for a given pyenv command
init Configure the shell environment for pyenv
install Install a Python version using python-build
local Set or show the local application-specific Python version
prefix Display prefix for a Python version
rehash Rehash pyenv shims [run this after installing executables]
root Display the root directory where versions and shims are kept
shell Set or show the shell-specific Python version
shims List existing pyenv shims
uninstall Uninstall a specific Python version
--version Display the version of pyenv
version Show the current Python version and its origin
version-file Detect the file that sets the current pyenv version
version-name Show the current Python version
version-origin Explain how the current Python version is set
versions List all Python versions available to pyenv
virtualenv Create a Python virtualenv using the pyenv-virtualenv plugin
virtualenv-delete Uninstall a specific Python virtualenv
virtualenv-init Configure the shell environment for pyenv-virtualenv
virtualenv-prefix Display real_prefix for a Python virtualenv version
virtualenvs List all Python virtualenvs found in `$PYENV_ROOT/versions/*'.
whence List all Python versions that contain the given executable
which Display the full path to an executable
See `pyenv help ' for information on a specific command.
For full documentation, see: //github.com/pyenv/pyenv#readme
Nhìn vào các phiên bản Python
$ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
Cài đặt một con trăn mới
$ pyenv install 3.7.0
Installing Python-3.7.0...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
Nếu bạn gặp sự cố với thư viện Libffi-Dev cài đặt _ctypes
Bây giờ hãy nhìn vào các phiên bản
$ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
3.7.0
Chọn 3.7.0 cho môi trường địa phương
$ pyenv local 3.7.0
Thấy rằng phiên bản đã thay đổi
$ pyenv versions
system
3.6.7
* 3.7.0 [set by /home/taarimalta/.python-version]
$ python
Python 3.7.0 [default, Jan 1 2020, 10:52:57]
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Chuyển sang một thư mục khác
cd ../project2
pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
3.7.0
Phiên bản Python có thể khác ở đây tùy thuộc vào phiên bản Python bạn đã đặt cục bộ
Đặt phiên bản pyenv trên toàn cầu
Điều này toàn cầu đặt phiên bản Python cho người dùng
pyenv global 3.7.0
Lưu ý rằng PyENV đặt phiên bản cục bộ bằng cách thêm tệp .Python-forse
$ pyenv local 3.7.0
$ cat .python-version
3.7.0
Lưu ý rằng Pyenv biết phiên bản toàn cầu bằng cách xem tệp
$ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
4$ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
0 Tôi cần thay đổi phiên bản Python của mình từ 3,8 thành 3,6? Làm thế nào tôi có thể đạt được điều này trong Ubuntu 20.04. Tôi đã thử pyenv, nhưng khi tôi cố gắng sử dụng pyenv như
$ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
5 thì tôi làm $ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
6 và tôi vẫn còn 3,8 phần xác thực.Đã hỏi ngày 3 tháng 11 năm 2021 lúc 18:41Nov 3, 2021 at 18:41
3
Đừng hạ cấp phiên bản hệ thống: Có khả năng một số phần của hệ thống sẽ ngừng hoạt động. Không bao giờ thay đổi
$ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
7 và tránh đặt phiên bản $ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
6 cũ hơn trước $ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
9.Lưu trữ Deadnakes cung cấp các gói của các phiên bản Python được hỗ trợ nhất cho các phiên bản Ubuntu LTS hiện được hỗ trợ. Để cung cấp các gói này, hãy làm theo các hướng dẫn thông thường để bật PPA. Sau đó cài đặt [các] gói bạn muốn.
$ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
1Sau đó, bạn có thể tạo một môi trường ảo cho phiên bản Python đã chọn và với một bộ gói được chọn.
$ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
2Để chạy một chương trình trong môi trường này, hãy tìm tập lệnh
$ pyenv install 3.7.0
Installing Python-3.7.0...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
0 trong vỏ.$ pyenv versions
system
* 3.6.7 [set by /home/taarimalta/.pyenv/version]
3Đã trả lời ngày 3 tháng 11 năm 2021 lúc 19:11Nov 3, 2021 at 19:11
Ngoài ra, bạn có thể tạo một môi trường ảo.
Giả sử bạn đã cài đặt Python 3.8 [hoặc cao hơn] trên hệ thống, nhưng đối với một nhiệm vụ cụ thể, bạn cần Python 3.7 [hoặc thấp hơn]. Ý tưởng tốt nhất là [không hạ cấp] để tạo môi trường ảo với Python 3.7 [hoặc bất kỳ 3.x nào, thay đổi các lệnh bên dưới theo phiên bản mong muốn của bạn. Dưới đây là triển khai môi trường ảo với Python 3.7]3.8 [or higher] installed on the system, but for a specific task, you need python 3.7 [or lower]. The best idea is [not to downgrade] to Create a virtual environment with python 3.7[or any 3.x, change the commands below according to your desired version. Below is an implementation of a virtual environment with python 3.7]
Các bước: [đã kiểm tra tháng 8 năm 2022]
Cài đặt Python 3.7 và các gói môi trường ảo của nó.
1$ pyenv install 3.7.0 Installing Python-3.7.0... WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib? WARNING: The Python readline extension was not compiled. Missing the GNU readline lib? WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
Tìm ra vị trí của Python 3.7 của bạn theo lệnh này:
2 [nên là một cái gì đó như /usr/bin/python3.7, nếu không tìm thấy, sau đó cài đặt Python 3.7 theo cách thủ công]/usr/bin/python3.7, if not found, then install python 3.7 manually]$ pyenv install 3.7.0 Installing Python-3.7.0... WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib? WARNING: The Python readline extension was not compiled. Missing the GNU readline lib? WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
Tạo môi trường ảo trong thư mục nhà.
3$ pyenv install 3.7.0 Installing Python-3.7.0... WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib? WARNING: The Python readline extension was not compiled. Missing the GNU readline lib? WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
4$ pyenv install 3.7.0 Installing Python-3.7.0... WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib? WARNING: The Python readline extension was not compiled. Missing the GNU readline lib? WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
5$ pyenv install 3.7.0 Installing Python-3.7.0... WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib? WARNING: The Python readline extension was not compiled. Missing the GNU readline lib? WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
6$ pyenv install 3.7.0 Installing Python-3.7.0... WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib? WARNING: The Python readline extension was not compiled. Missing the GNU readline lib? WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
7 [nên là Python 3.7 bây giờ]$ pyenv install 3.7.0 Installing Python-3.7.0... WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib? WARNING: The Python readline extension was not compiled. Missing the GNU readline lib? WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
Xong. Python 3.7 có thể được sử dụng trong môi trường ảo này. Loại
8, bạn sẽ thấy bạn đã tạo Python 3.7 trong một môi trường ảo, thay vì trong hệ thống trên toàn cầu.$ pyenv install 3.7.0 Installing Python-3.7.0... WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib? WARNING: The Python readline extension was not compiled. Missing the GNU readline lib? WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
Chạy
9 khi bạn cần hủy kích hoạt.$ pyenv install 3.7.0 Installing Python-3.7.0... WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib? WARNING: The Python readline extension was not compiled. Missing the GNU readline lib? WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
Đã trả lời ngày 19 tháng 8 lúc 9:16Aug 19 at 9:16