3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VisualStudioCodeでPythonの環境を作る

Last updated at Posted at 2021-03-29

参考記事:https://www.python.jp/python_vscode/windows/index.html

事前に!!

AnacondaなどPythonの実行環境が入っていたらアンインストールしておく
コントロールパネルを確認してみたら大量にPythonが入っていた

image.png

Window10でPythonをインストールする

Pythonの公式ページのダウンロードページからインストールを行う。

image.png

image.png

Add Python to Pathにチェックを入れる

もし忘れてインストールした場合は、アンインストールしてからやり直す
image.png

image.png

PowerShellでスクリプトの実行を許可しておきます。

スタートメニューで Windows PowerShell | Windows PowerShell を起動し、次のコマンドを実行します。

hoge.txt
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

このコマンドは、一番最初に一回だけ実行してください。2回目以降は不要です。

image.png

テスト実行してみる
image.png

VisualStudioCodeでの設定

拡張機能をインストール
[ファイル]-[ユーザー設定]-[拡張機能]

image.png

Linter機能を無効にします。

VS Codeの表示メニューから、コマンドパレット... を選択する。

hoge.txt
Python: select linter

と入力して、表示される Python: Select Linter をクリックします。
image.png

続いて表示される一覧から、 Disable Linting を選択する
image.png

VScode上で実行する

実行するときは右上の▶マークを押すことで実行される

image.png

PySimpleGUIをインストールする

VisualStudioCodeの[Terminal]-[NewTeaminal]でPowerShellを実行する
image.png

hoge.txt
pip install pysimplegui

pipのパスが通っていないとエラーが発生するが、上記の通りインストール時にパスを通しているのでVisualStudioCodeを再起動すればOK。
image.png

再起動したらpipをアップグレードする

hoge.py
python -m pip install --upgrade pip

サンプルプログラムを実行する

サンプルプログラムを持ってきて実行すると、画面が表示された

image.png

タスクスケジューラーでPythonを実行する

WindowsのタスクスケジューラーでPythonを実行するためには、以下のように設定します

■プログラム/スクリプト:python.exeのパス
C:\Users\Administrator\AppData\Local\Programs\Python\Python39\python.exe

■引数の追加:pythonファイル名
Scrap.py

■開始(オプション):pythonファイルがある場所
C:\Users\Administrator\Documents\Python\

Python.exeがどこにあるのかを確認する

コマンドプロンプトで実行

hoge.txt
py --list-paths

image.png

デバッグを実行する

image.png

image.png

image.png

image.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?