Pythonのインストールが終わってない場合はhttps://jigya.net/python-install/を参考にPythonのインタプリタをインストールをする必要がある
VSCode(Visual Studio Code)のダウンロード
https://code.visualstudio.com/download
↑から自分のOSにあったダウンロードを行う
(※自分の環境はwin10の64bitなので一番左のWindowsを選択)

利用ブラウザで設定されているダウンロードファイルの保存先にインストーラーが保存される
初期設定だとダウンロード(download)フォルダが普通?
VSCode(Visual Studio Code)のインストール
ダウンロードしたインストーラーをダブルクリックしてインストール開始







VSCodeの設定
VSCodeを起動する

日本語化
左のアクティビティバーにある拡張機能アイコンをクリック
拡張機能のサイドバーが開く(候補のトップにはすでに「Python」が)

検索エリア(「Search Extensions in Marketplace」)に「Japanese」と入力すると
検索結果のトップに「Japanese Language …」が表示される

「Japanese Language …」と表示されているタグ?をクリックするとメインウィンドウに詳細が表示されるので、「Japanese Language Pack for Visual Studio Code」であることを確認して「Install」をクリックするとインストールが始まる

インストールが完了すると「Install」だった箇所がサイドバーは設定の歯車アイコンに、メインウィンドウは「Uninstall」に変わっている

インストールが確認後、再起動してメニューバーが日本語になっていれば日本語化完了

Pythonインストール
日本語化の時と同じ様に左のアクティビティバーにある拡張機能アイコンをクリック
検索エリア(「Search Extensions in Marketplace」)に「Python」と入力すると
検索結果のトップに「Python」が表示される

「Python」と表示されているタグ?をクリックするとメインウィンドウに詳細が表示されるので、インストールしたいバージョンであることを確認して「インストール」をクリックするとインストールが始まる

インストールが完了すると「インストール」だった箇所がサイドバーは設定の歯車アイコンに、メインウィンドウは「アンインストール」に変わっていればインストール完了
PythonをインストールするとPylanceとJupyter一式が同時にインストールされる
実行やデバッグについて私はターミナルで行うのでJupyter一式はアンインストールしています
Jupyter利用する方はアンインストールはしなくてOKです
Pylanceはあった方が断然良いので残してる

動作確認(hello world)
ファイルの作成
あらかじめ任意の場所にPythonという名のフォルダを作成する(例えばドキュメントフォルダ内に作成)
メニューバーの「ファイル」→「フォルダを開く」をクリック
あらかじめ作成しておいたPythonのフォルダを選択
エクスプローラーのサイドバーが開く

「新しいファイル…」をクリックし、test.pyというファイルにする
ファイルが作成されるとメインのウィンドウに今作成したファイルが表示される(最初なので何も表示されない)

開かれたファイルに
print("hello world")
を入力する

実行
いつもコマンドプロンプトで実行しているので同じやり方で。。。
VSCodeウィンドウの下の方にターミナルが出ていなければ[Ctrl]+[@]でターミナルが表示される

上記の例だとpowershellになっているが、そのままやっても大丈夫。一応コマンドプロンプトに変更する方法も記載しておく
「powershell」と記載のある右隣の「+」のさらに右隣の「∨」をクリックしてドロップダウンリストから[CommandPrompt]を選択するとcmdが追加される

右側の[powershell]、[cmd]をクリックすることで切り替え可能
ちなみに「+」で[powershell]や[cmd]をさらに追加することも可能

ここからはさらにどうでもいいが、powershell使わないので消したいときは
[powershell]にカーソルを持っていくと表示される「ごみ箱マーク」をクリックすることで削除できる


コマンドプロンプトで
python test.py
と入力して[Enter]キーを押すと、入力した下に「hello world」と表示されれば動作確認完了となる

コメント