0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCode + Jupyter Notebook 環境構築の記録(Python3.11 → 3.12)

Last updated at Posted at 2025-08-20

前提条件

  • VSCodeはインストール済み
  • Pythonは3.11のみインストール済み(今回新しく3.12もインストール)
  • Windows環境で作業

1. Python3.11からPython3.12へのバージョンアップ

背景

以前まではPython3.11を利用していたが、3.12にも慣れておく必要があると思いバージョンアップを検討。

手順

  • Python3.12を公式サイトからインストール
    https://www.python.org/downloads/windows/
  • VSCodeで作業フォルダへ移動
  • ターミナルでPython3.12があることを確認
    PS C:\Users\****\Desktop\cat_category\test> py -0
     -V:3.12 *        Python 3.12 (64-bit)
     -V:3.11          Python 3.11 (64-bit)
  • 仮想環境を作成
    PS C:\Users\****\Desktop\cat_category\test> py -3.12 -m venv venv

※今回利用したいライブラリが3.12に対応していなかったため、最終的にPython3.11で環境構築を行いました。

2. ライブラリのインストール

背景

requirements.txt を使ったライブラリのインストールを初めて挑戦。

手順

  • 仮想環境の実行
    PS C:\Users\yaku2\OneDrive\デスクトップ\cat_category\test> .\venv\Scripts\activate.bat 
  • pipのアップグレード
    PS C:\Users\****\Desktop\cat_category\test> python -m pip install --upgrade pip
    Requirement already satisfied: pip in ... (22.3)
    Collecting pip
      Downloading pip-25.2-py3-none-any.whl (1.8 MB)
    Installing collected packages: pip
      Attempting uninstall: pip
        Found existing installation: pip 22.3
        Uninstalling pip-22.3:
          Successfully uninstalled pip-22.3
    Successfully installed pip-25.2
  • ライブラリのインストール
    PS C:\Users\****\Desktop\cat_category\test> pip install -r requirements.txt

当初インストール予定のライブラリ

numpy==1.24.3
pandas==2.0.2
matplotlib==3.7.1
seaborn==0.12.2
ipython==8.13.2
jupyter==1.0.0
torch==2.1.0
torchvision==0.15.2
Pillow==10.0.0
opencv-python==4.8.1.78
scikit-learn==1.3.0
tqdm==4.66.1
albumentations==1.3.1

エラー発生

ERROR: Ignored the following yanked versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.2.post2, 0.2.2.post3, 0.15.0
ERROR: Ignored the following versions that require a different python version: 1.21.2 Requires-Python >=3.7,<3.11; ...
ERROR: Could not find a version that satisfies the requirement torchvision==0.18.2
ERROR: No matching distribution found for torchvision==0.18.2

→ torchvision==0.18.2 がPython3.11では利用できないため、バージョンを調整しました。

修正版ライブラリ

numpy==1.24.3
pandas==2.0.2
matplotlib==3.7.1
seaborn==0.12.2
ipython==8.13.2
jupyter==1.0.0
torch==2.0.1
torchvision==0.15.2
Pillow==10.0.0
opencv-python==4.8.1.78
scikit-learn==1.3.0
tqdm==4.66.1
albumentations==1.3.1

これで無事にインストールが完了し、VSCode上でJupyter Notebookが使える環境が整いました。

3. 仮想環境の立ち上げ方

py -3.11 -m venv venv

.\venv\Scripts\Activate.ps1

🔎 詳しくいうと

python -m venv venv を実行すると、venv というフォルダが作られます。

その中に「実行用のスクリプト」が保存されます:

  • Windows (PowerShell): venv\Scripts\Activate.ps1
  • Windows (コマンドプロンプト): venv\Scripts\activate.bat
  • Linux / Mac (bash/zsh): venv/bin/activate

.\venv\Scripts\Activate.ps1 を実行すると、そのシェル内で「仮想環境のPython」を優先的に使うように設定されます。

Jupyter Notebook で使う準備

pip install ipykernel

ipykernel は Jupyter Notebook / Jupyter Lab から、その仮想環境を Python カーネルとして使えるようにするためのパッケージです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?