본문 바로가기

개발하자

VSCode Jupyter가 잘못된 버전의 python을 로드합니다.

반응형

VSCode Jupyter가 잘못된 버전의 python을 로드합니다.

VSCode의 주피터는 화면 왼쪽 아래에 표시되는 파이썬 버전을 실제로 실행하지 않습니다.

아래에서는 3.9.1을 실행하고 있다고 주장하지만, 셀의 출력은 실제로 3.7.9를 실행하고 있음을 보여준다.

다음을 통해 표시된 환경을 선택했습니다.

작동하지 않는 것:

  • Jupyter 커널 재시작
  • 다른 환경 선택(env의 python에 관계없이 모두 실제로 3.7.9를 실행함)

incorrect version of python

추가 정보:

Python 출력:

> conda --version
> pyenv root
> python3.7 ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~/.local/share/miniconda3/envs/rl/bin/python ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> conda info --json
Starting Pylance language server.
Python interpreter path: ~/.local/share/miniconda3/envs/rl/bin/python
> conda env list
> conda env list

예, 마지막으로 나열된 인터프리터는 v3.9.1입니다.

% ~/.local/share/miniconda3/envs/rl/bin/python --version
Python 3.9.1

주피터 출력:

User belongs to experiment group 'jupyterTest'
> ~/.local/share/miniconda3/envs/rl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py -c "import notebook"
> ~/.local/share/miniconda3/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py -c "import jupyter"
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py jupyter kernelspec --version
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~/.local/share/miniconda3/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
> ~/.local/share/miniconda3/envs/rl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
Started kernel Python 3
> ~/.local/share/miniconda3/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v

마지막으로 나열된 파이썬은 선택되지 않은 잘못된 버전입니다.

% ~/.local/share/miniconda3/bin/python --version
Python 3.7.9

올바른 버전이 바로 위에 나열되어 있는데 왜 이 버전이 사용됩니까?




VSCode에서 Jupyter 노트북의 Python 환경은 독립적이며, 지난 번에 선택한 Python 환경을 기본적으로 사용합니다. 오른쪽 상단 모서리에 있는 " "를 클릭하고 파이썬 3.9 환경으로 전환할 수 있습니다.

Python 환경을 전환한 후에 VScode를 다시 로드하여 Jupyter가 해당 커널을 다시 로드하도록 하십시오.

enter image description here




결국 저에게 효과가 있었던 것은 다음과 같습니다.

  1. VS 코드 닫기
  2. 창의 오른쪽 상단에서 Python 버전을 원하는 conda 환경으로 변경합니다.
  3. 커널 시작

커널을 변경한 다음 다시 시작하는 것은 작동하지 않는 것처럼 보였다.




https://www.it-swarm-vi.com/vi/python/ipynb-nhap-tap-tin-ipynb-khac/1042793988/

!pip install import_ipynb`enter code here`
!pip install ipynb

import import_ipynb
import ipynb

from ipynb.fs.full.tim_folder import tim_folder



나는 콘다를 위한 환경을 만들 때 파이썬 버전을 지정하려고 시도한 적이 있다.

conda env create -f environment.yml python={version}

일반적으로 최신 버전을 설치하고 명령을 무시합니다.

enter image description here

이 문제를 해결하려면 환경을 활성화합니다.

그런 다음 올바른 버전을 설치합니다.

수집한 주요 이점은 VSCode UI에서 커널 환경을 선택할 수 있는 옵션을 제공하고 해당 환경으로 전환할 수 있는 경로를 제공합니다. 내가 그 디렉토리에 들어갔을 때 파이썬 버전은 없었다. 설치하고 VScode를 재부팅합니다.


반응형