Nội dung chính
Pyenv
Thay đổi môi trường mặc định của trình thông dịch PythonPython interpreter
Cú pháp
Sự mô tả
Sử dụng pyenv
để thay đổi phiên bản mặc định hoặc chế độ thực thi của trình thông dịch Python®. Những thay đổi này vẫn tồn tại trong các phiên MATLAB® khác nhau.
Ghi chú
MATLAB tự động tải Python khi bạn nhập py.
command
. Bạn không thể thay đổi trình thông dịch sau khi MATLAB tải Python. Để thay đổi trình thông dịch, khởi động lại MATLAB và sau đó gọi pyenv
.
thí dụ
pyenv
hiển thị chi tiết về môi trường Python [mặc định] hiện tại. displays details about the current [default] Python environment.
thí dụ
pyenv
hiển thị chi tiết về môi trường Python [mặc định] hiện tại. specifies parameters for setting the Python
environment. For example,
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: NotLoaded ExecutionMode: OutOfProcess1 changes the default Python version on Microsoft® Windows® platforms to 2.7.
ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
0] Chỉ định các tham số để thiết lập môi trường Python. Ví dụ: ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
1 thay đổi phiên bản Python mặc định trên nền tảng Microsoft® Windows® thành 2.7. additionally returns environment details as a
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: NotLoaded ExecutionMode: OutOfProcess3 object. Use this syntax with any of the arguments in previous syntaxes.
ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
2 Ngoài ra trả về chi tiết môi trường dưới dạng đối tượng ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
3. Sử dụng cú pháp này với bất kỳ đối số nào trong các cú pháp trước đó.
Ví dụ
sụp đổ tất cảPython Version for Your System
Hiển thị phiên bản Python cho hệ thống của bạn
Tạo
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: NotLoaded ExecutionMode: OutOfProcess4 Biến ngoài quá trình
pyenv["ExecutionMode","OutOfProcess"]
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: NotLoaded ExecutionMode: OutOfProcess
Đặt chế độ thực thi thành
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: NotLoaded ExecutionMode: OutOfProcess5.
py.list[{'Monday','Tuesday','Wednesday','Thursday','Friday'}];
Tạo biến.
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: Loaded ExecutionMode: OutOfProcess ProcessID: "8196" ProcessName: "MATLABPyHost"
Hiển thị quá trình. MATLAB hiển thị thông tin cụ thể cho môi trường của bạn.Python Version 2.7
pe = pyenv; if pe.Status == 'Loaded' disp['To change the Python version, restart MATLAB, then call pyenv['Version','2.7'].'] else pyenv['Version','2.7']; end
Sử dụng phiên bản Python 2.7Python Is Installed
Kiểm tra Python được cài đặt
pe = pyenv; if pe.Version == "" disp "Python not installed" end
Để xác minh xem Python có được cài đặt trên hệ thống của bạn không, hãy kiểm tra thuộc tính ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
3 ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
7.
Ví dụ
sụp đổ tất cả
Hiển thị phiên bản Python cho hệ thống của bạn
Tạo ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
4 Biến ngoài quá trình
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: NotLoaded ExecutionMode: OutOfProcess9 in quotes.
Đặt chế độ thực thi thành ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
5.py.list[{'Monday','Tuesday','Wednesday','Thursday','Friday'}];
2
Tạo biến.Python version or executable
string | character vector
Hiển thị quá trình. MATLAB hiển thị thông tin cụ thể cho môi trường của bạn.
Sử dụng phiên bản Python 2.7
Kiểm tra Python được cài đặt
Để xác minh xem Python có được cài đặt trên hệ thống của bạn không, hãy kiểm tra thuộc tính ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
3 ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
7.
py.list[{'Monday','Tuesday','Wednesday','Thursday','Friday'}];8
Đối số đầu vào
py.list[{'Monday','Tuesday','Wednesday','Thursday','Friday'}];9
Đối số giá trị tên
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: Loaded ExecutionMode: OutOfProcess ProcessID: "8196" ProcessName: "MATLABPyHost"0 |
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: Loaded ExecutionMode: OutOfProcess ProcessID: "8196" ProcessName: "MATLABPyHost"1
Chỉ định các cặp đối số tùy chọn là ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
8, trong đó ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
9 là tên đối số và py.list[{'Monday','Tuesday','Wednesday','Thursday','Friday'}];
0 là giá trị tương ứng. Các đối số giá trị tên phải xuất hiện sau các đối số khác, nhưng thứ tự của các cặp không quan trọng.Execution mode
ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: Loaded
ExecutionMode: OutOfProcess
ProcessID: "8196"
ProcessName: "MATLABPyHost"
3 [default] | ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: Loaded
ExecutionMode: OutOfProcess
ProcessID: "8196"
ProcessName: "MATLABPyHost"
4
Trước R2021A, hãy sử dụng dấu phẩy để phân tách từng tên và giá trị và gửi
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: NotLoaded ExecutionMode: OutOfProcess9 trong trích dẫn.
Ví dụ:
py.list[{'Monday','Tuesday','Wednesday','Thursday','Friday'}];2
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: NotLoaded ExecutionMode: OutOfProcess
7 - Phiên bản Python hoặc Executablestring | vector ký tựSố phiên bản Python [chỉ có nền tảng Windows] hoặc tên tệp có thể thực thi, được chỉ định là chuỗi hoặc vectơ ký tự. Để biết thông tin về các phiên bản được hỗ trợ, hãy xem Cấu hình hệ thống của bạn để sử dụng Python.
Nếu
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: NotLoaded ExecutionMode: OutOfProcess7 chỉ định một số, thì giá trị phải chứa các số phiên bản chính và nhỏ được phân tách theo một khoảng thời gian. Chức năng tìm kiếm phiên bản trong sổ đăng ký Windows. Nếu bạn tải xuống ứng dụng Python từ
py.list[{'Monday','Tuesday','Wednesday','Thursday','Friday'}];5, thì việc cài đặt sẽ tự động thêm phiên bản vào sổ đăng ký. Nếu bạn tải xuống ứng dụng từ một nguồn khác, bạn phải thêm phiên bản vào sổ đăng ký hoặc gọi
pyenv
với tên tệp thực thi để thay đổi phiên bản.Đối số giá trị tên
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: Loaded ExecutionMode: OutOfProcess ProcessID: "8196" ProcessName: "MATLABPyHost"0 |
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: Loaded ExecutionMode: OutOfProcess ProcessID: "8196" ProcessName: "MATLABPyHost"1
Chỉ định các cặp đối số tùy chọn là ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
8, trong đó ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
9 là tên đối số và py.list[{'Monday','Tuesday','Wednesday','Thursday','Friday'}];
0 là giá trị tương ứng. Các đối số giá trị tên phải xuất hiện sau các đối số khác, nhưng thứ tự của các cặp không quan trọng.
Trước R2021A, hãy sử dụng dấu phẩy để phân tách từng tên và giá trị và gửi ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "C:\Python27\pythonw.exe"
Library: "C:\windows\system32\python27.dll"
Home: "C:\Python27"
Status: NotLoaded
ExecutionMode: OutOfProcess
9 trong trích dẫn.