2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Raspberry PiでPythonの環境を構築する方法

2
Posted at

Raspberry PiでPythonの環境を構築する方法をご紹介します。

対象環境

  • Raspberry Pi 4 (他モデルでも問題なし)
  • Raspberry Pi OS Bookworm(最新版)
  • インターネット接続環境
  • ターミナル操作ができること(SSH または HDMI 接続)
  • Raspberry Piのセットアップが完了していること

手順の全体像

  1. Python 開発環境の構築
  2. サンプルプログラムの作成
  3. 実行

1. Python 開発環境の構築

Pythonはデフォルトでインストールされています。
必要な方は以下のコマンドでインストールします。

sudo apt update
sudo apt install -y python3 python3-pip python3-venv

2. サンプルプログラムの作成

作業用ディレクトリを作成して移動します。

mkdir -p ~/python_samples && cd ~/python_samples

次にエディタでソースコードファイルを作成します。

nano hello.py

内容は以下のとおりです。

print("Hello, Raspberry Pi!")

3. 実行

以下のコマンドで作成したプログラムを実行します。

python3 hello.py
Hello, Raspberry Pi!

と表示されます。

4. まとめ

Pythonの開発環境を構築し、サンプルプログラムを動かすことができました。
よろしければ、いいね、ストック、コメントいただけますと幸いです。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?