pythonのコードを実行する方法
pythonで書いたコードを実行する方法
- python script.py
- ./script.py
前提:pythonはインストール済み
pythonの環境構築に関してはこちら
 Visual Studio Codeでpythonコーディング
Visual Studio Codeでpythonコーディング
 M1 MacにJupyter notebookをインストールする方法
M1 MacにJupyter notebookをインストールする方法
まずはpythonが入っているかを確認する
# which python
/usr/bin/python
上のwhichで出てこない場合
# dpkg -S python | grep "/bin/"                                               
python3.10-minimal: /usr/bin/python3.10                                                             │sdb    8:16   0  256G  0 disk /
python3-dotenv: /usr/bin/python-dotenv                                                              │root@DESKTOP-R3EPJBD:~# de -h
python3-babel: /usr/bin/pybabel-python3                                                             │de: command not found
python3-dev: /usr/bin/python3-config                                                                │root@DESKTOP-R3EPJBD:~# df -h
python3-minimal: /usr/bin/python3
pythonで出ない場合は大抵python3とかではいってる
# which python3
/usr/bin/python3
# dpkg -S $(which python3)
python3-minimal: /usr/bin/python3
下記のスクリプトを作成
# cat test.py
print("python")
python3コマンドで実行
# python3 test.py
python
./で実行
ファイルに実行権限をつけてファイルの先頭にシバンをつける
# ls -al test.py
-rw-r--r-- 1 root root 17 Nov 22 18:05 test.py
# chmod 755 test.py
# ls -al test.py
-rwxr-xr-x 1 root root 17 Nov 22 18:05 test.py
# sed -i '1i#!/usr/bin/python3' test.py
# cat test.py
#!/usr/bin/python3
print("python")
# ./test.py
python

