Hướng dẫn why python interpreter is not showing in vs code? - tại sao trình thông dịch python không hiển thị trong mã so với mã?

Tôi đã có vấn đề tương tự này, nhưng tôi đã tìm thấy một giải pháp khác;

Trong Cài đặt.json, tôi đã có "python.defaultinterpreterpath": "d: \ files chương trình \ python310 \ python.exe" nhưng ngay cả điều này cũng bị bỏ qua vì một số lý do!
"python.defaultInterpreterPath": "D:\Program Files\Python310\python.exe" but even this was getting ignored for some reason!

Vì vậy, tôi đã nhìn vào $ ENV: Đường dẫn trong PowerShell được tải trong VSCODE và $ ENV: Đường dẫn trong CommandLine PowerShell tiêu chuẩn trong Windows và chúng khác nhau!

Có vẻ như nếu bạn có một thiết bị đầu cuối mở trong VSCODE, nó sẽ nhớ $ env từ thiết bị đầu cuối đó, ngay cả khi bạn khởi động lại hoàn toàn VSCODE hoặc ngay cả khi bạn khởi động lại máy tính của mình.

Những gì làm việc cho tôi (do tai nạn) là, đóng tất cả các cửa sổ thiết bị đầu cuối (và có thể bất cứ thứ gì khác liên quan đến thiết bị đầu cuối/PowerShell mở) và thử lại!

Nếu nó vẫn không hoạt động, hãy so sánh các giá trị đường dẫn $ env: và xem liệu chúng có còn khác không!

Có thể liên quan đến #15155?

Dữ liệu môi trường

  • Phiên bản mã vs: 1.54.3
  • Phiên bản mở rộng: 2020.10.332292344
  • HĐH và phiên bản: Linux x64 5.11.13-arch2-1
  • Phiên bản Python: Python 3
  • Loại môi trường ảo được sử dụng: Conda
  • Các gói Python có liên quan/bị ảnh hưởng và các phiên bản của chúng: N.A.
  • Các phần mở rộng mã liên quan đến Python có liên quan/bị ảnh hưởng và các phiên bản của chúng: N.A. (Vô hiệu hóa tất cả các tiện ích mở rộng khác)
  • Giá trị của cài đặt python.languageServer: Jedi

Hành vi mong đợi

Trình thông dịch Python trong thanh trạng thái

Hướng dẫn why python interpreter is not showing in vs code? - tại sao trình thông dịch python không hiển thị trong mã so với mã?

Hành vi thực tế

Không có thông dịch viên Python trong thanh trạng thái

Hướng dẫn why python interpreter is not showing in vs code? - tại sao trình thông dịch python không hiển thị trong mã so với mã?

Các bước để sinh sản:

  1. Bắt đầu VS Code (như bình thường)
  2. Mở bất kỳ tệp python hoặc máy tính xách tay Jupyter nào

Hành vi mong đợi có thể đạt được như sau

  1. Bắt đầu VS CODE bằng cờ --enable-proposed-api ms-python.python
  2. Mở bất kỳ tệp python hoặc máy tính xách tay Jupyter nào

Hành vi mong đợi có thể đạt được như sau

Bắt đầu VS CODE bằng cờ --enable-proposed-api ms-python.python

User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'pythonaacf'
User belongs to experiment group 'pythonSendEntireLineToREPL'
User belongs to experiment group 'pythonNotDisplayLinterPrompt'
User belongs to experiment group 'pythonDiscoveryModuleWithoutWatcher'
User belongs to experiment group 'pythonTensorboardExperiment'
> pyenv root
> python3.7 ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> /opt/miniconda/bin/conda info --json
Error 2021-04-15 10:17:52: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file '~/.config/Code/User/settings.json' (Error: Unable to resolve non-existing file '~/.config/Code/User/settings.json')
	at _handleError (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:87:151863)
	at processTicksAndRejections (internal/process/task_queues.js:97:5)
	at async y.readText (~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:9:168994)
	at async p.doesFileNeedToBeFixed (~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:56:963651)
	at async ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:56:962778
	at async Promise.all (index 0)
	at async p.getFilesToBeFixed (~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:56:962724)
	at async p.updateTestSettings (~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:56:962351)] {
  code: 'FileNotFound'
}
> /opt/miniconda/bin/conda env list
Python interpreter path: /opt/miniconda/bin/python
Error 2021-04-15 10:17:52: Python Extension: interpreterManager.refresh [Error: [ms-python.python]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ms-python.python
	at f (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:87:74959)
	at Object.g [as checkProposedApiEnabled] (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:87:74906)
	at Object.get activeNotebookEditor [as activeNotebookEditor] (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:95:39978)
	at u.get activeNotebookEditor [as activeNotebookEditor] (~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:56:1203223)
	at u.get hidden [as hidden] (~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:56:647038)
	at ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:56:846357
	at Array.every (<anonymous>)
	at g.updateVisibility (~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:56:846345)
	at g.updateDisplay (~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:56:846218)
	at async g.refresh (~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:56:845171)]
Starting Jedi Python language engine.
> /opt/miniconda/bin/conda env list
> ~/.conda/envs/dlnn/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import jupyter"
> ~/.conda/envs/dlnn/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import notebook"
> ~/.conda/envs/dlnn/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py jupyter kernelspec --version
> ~/.conda/envs/dlnn/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~/.conda/envs/dlnn/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~/.conda/envs/dlnn/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~/.conda/envs/dlnn/bin/python (daemon) -m jupyter notebook --no-browser --notebook-dir="~" --config=/tmp/acac0421-5df1-4f15-ac8d-9acf1f430ca1/jupyter_notebook_config.py --NotebookApp.iopub_data_rate_limit=10000000000.0
> ~/.conda/envs/dlnn/bin/python (daemon) -m jupyter kernelspec list --json
> ~/.conda/envs/dlnn/bin/python (daemon) -m jupyter kernelspec list --json
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py pylint --disable=all --enable=F,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,E0001,E0011,E0012,E0100,E0101,E0102,E0103,E0104,E0105,E0107,E0108,E0110,E0111,E0112,E0113,E0114,E0115,E0116,E0117,E0118,E0202,E0203,E0211,E0213,E0236,E0237,E0238,E0239,E0240,E0241,E0301,E0302,E0303,E0401,E0402,E0601,E0602,E0603,E0604,E0611,E0632,E0633,E0701,E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1101,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1128,E1129,E1130,E1131,E1132,E1133,E1134,E1135,E1136,E1137,E1138,E1139,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,E1310,E1700,E1701 --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text ~/Downloads/lexer.py
cwd: ~/Downloads
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py pylint --disable=all --enable=F,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,E0001,E0011,E0012,E0100,E0101,E0102,E0103,E0104,E0105,E0107,E0108,E0110,E0111,E0112,E0113,E0114,E0115,E0116,E0117,E0118,E0202,E0203,E0211,E0213,E0236,E0237,E0238,E0239,E0240,E0241,E0301,E0302,E0303,E0401,E0402,E0601,E0602,E0603,E0604,E0611,E0632,E0633,E0701,E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1101,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1128,E1129,E1130,E1131,E1132,E1133,E1134,E1135,E1136,E1137,E1138,E1139,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,E1310,E1700,E1701 --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text ~/Downloads/lexer.py
cwd: ~/Downloads
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import pylint"
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import pylint"
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import pylint"
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import pylint"

Linter 'pylint' is not installed. Please install it or select another linter".
Error: Module 'pylint' not installed.
> ~/.conda/envs/dlnn/bin/python (daemon) ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/vscode_datascience_helpers/getJupyterKernels.py
> ~/.conda/envs/dlnn/bin/python (daemon) ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/vscode_datascience_helpers/getJupyterKernels.py
> ~/.conda/envs/dlnn/bin/python (daemon) ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/vscode_datascience_helpers/getServerInfo.py
> ~/.conda/envs/dlnn/bin/python (daemon) ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/vscode_datascience_helpers/getServerInfo.py
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py ipykernel install --user --name python37764bitbaseconda67b1fd21446a45aab81a5fea15778bb5 --display-name "Python 3.7.7 64-bit ('base': conda)"
> ~/.conda/envs/dlnn/bin/python (daemon) ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/vscode_datascience_helpers/getServerInfo.py
> ~/.conda/envs/dlnn/bin/python (daemon) ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/vscode_datascience_helpers/getServerInfo.py
Error 2021-04-15 10:17:53: Failed to register an interpreter as a kernel, Class name = I, completed in 406ms, has a falsy return value, Arg 1: {"architecture":3,"path":"/opt/miniconda/bin/python","version":{"options":{"loose":false,"includePrerelease":false},"loose":false,"raw":"3.7.7-final","major":3,"minor":7,"patch":7,"prerelease":["final"],"build":[],"version":"3.7.7-final"},"sysVersion":"3.7.7 (default, May  7 2020, 21:25:33) \n[GCC 7.3.0]","sysPrefix":"/opt/miniconda","fileHash":"034a381e15e1e780ca7f37cd9663c61b07e9b27fa240a71d34004d06c77a58e6adde8b3dc8b9d8980982f94c3408a9c4890afe144438e42439a8fe157d673ef9","companyDisplayName":"Anaconda, Inc.","envType":"Conda","envPath":"/opt/miniconda","envName":"base","displayName":"Python 3.7.7 64-bit ('base': conda)"}, Arg 2: true, Arg 3: <argument cannot be serialized for logging>, Return Value: undefined [r [Error]: Traceback (most recent call last):
  File "~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py", line 32, in <module>
    runpy.run_module(module, run_name="__main__", alter_sys=True)
  File "/opt/miniconda/lib/python3.7/runpy.py", line 201, in run_module
    mod_name, mod_spec, code = _get_module_details(mod_name)
  File "/opt/miniconda/lib/python3.7/runpy.py", line 136, in _get_module_details
    raise error("No module named %s" % mod_name)
ImportError: No module named ipykernel

	at ChildProcess.<anonymous> (~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:17:55746)
	at Object.onceWrapper (events.js:422:26)
	at ChildProcess.emit (events.js:315:20)
	at maybeClose (internal/child_process.js:1021:16)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)]
Error 2021-04-15 10:17:53: Error starting server in serverPreload:  [r [Error]: Traceback (most recent call last):
  File "~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py", line 32, in <module>
    runpy.run_module(module, run_name="__main__", alter_sys=True)
  File "/opt/miniconda/lib/python3.7/runpy.py", line 201, in run_module
    mod_name, mod_spec, code = _get_module_details(mod_name)
  File "/opt/miniconda/lib/python3.7/runpy.py", line 136, in _get_module_details
    raise error("No module named %s" % mod_name)
ImportError: No module named ipykernel

	at ChildProcess.<anonymous> (~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client/extension.js:17:55746)
	at Object.onceWrapper (events.js:422:26)
	at ChildProcess.emit (events.js:315:20)
	at maybeClose (internal/child_process.js:1021:16)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)]
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.prefix)"
cwd: ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.prefix)"
cwd: ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
cwd: ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
cwd: ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py site --user-site
cwd: ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py site --user-site
cwd: ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/out/client
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/completion.py
> /opt/miniconda/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/pyvsc-run-isolated.py ~/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/completion.py