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?

【Python】マリオを自作するための環境構築

Posted at

マリオをPythonで作成するハンズオン動画を見つけたので、まずは環境構築をしてみる。
参考:【#1 環境構築】マリオを一緒に作ってみませんか!pythonで!【ハンズオン実践解説】

Pythonをインストール

インストールの方法は以下を参考にする。
私はMiniCondaを採用した。

Pythonを直接インストールする場合

PythonをインストールしてPygameを動かすまで

Minicondaの場合

参考:Miniconda Install 備忘録

仮想環境構築

Pythonの仮想環境を構築することで、仮想環境ごとにバージョンを変えたりライブラリを追加できたりする。

pythonをサイトからインストールした場合

python3 -m venv mario10
source mario10/bin/activate
mario10¥Scripts¥activate

minicondaをインストールした場合

conda create -n mario10 python=3.11
conda activate mario10

初めてインストールする場合は、環境変数の設定が行われていない可能性があるので、以下を設定する。

Conda のパスを環境変数に追加(Windows)

手動で設定

  1. [Windows]キー + [R]キー を押し、「sysdm.cpl」と入力し、Enter
  2. 「詳細設定」タブ → 「環境変数」ボタンをクリック
  3. 「システム環境変数」の Path を選択し、「編集」
  4. 以下のフォルダパスを追加(Minicondaの場合)
    C:\Users\user\miniconda3
    C:\Users\user\miniconda3\Scripts
    C:\Users\user\miniconda3\Library\bin
    
  5. 「OK」→ PCを再起動

Pygame をインストール

以下のコマンドを実行:

python -m pip install pygame

インストール確認

インストールが完了したら、pygame が正しく動作するか確認します。

python -m pygame.examples.aliens

エイリアンのミニゲームが起動すれば成功

または、Python を開いて以下を試す:

import pygame
print(pygame.__version__)

pygame 2.x.x などのバージョンが表示されればOK!

VSCodeの設定

VSCodeのインストールは以下参照
参考:Python,VScodeインストール

Python 拡張機能をインストール**

VS Code で Python を快適に使うには、Python 拡張機能 が必要です。

  1. 左の拡張機能アイコン(Ctrl + Shift + X)をクリック
  2. 検索バーに Python と入力
  3. Python (Microsoft) を選択して「インストール」
  4. インストール後、VS Code を再起動

仮想環境を VS Code に設定

作成した mario10 仮想環境 を VS Code で使えるようにします。

  1. [Ctrl + Shift + P] を押す → 「コマンドパレット」が開く
  2. 「Python: Select Interpreter」を検索して選択
  3. mario10 を選択
    • C:\Users\user\miniconda3\envs\mario10\python.exe などが表示されるはず

成功すると、VS Code の右下に mario10 が表示される

まとめ

ChatGPTを使って何とか環境構築が完了した。
次はWindow表示にチャレンジしたいと思います。

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?