LoginSignup
6
4

More than 3 years have passed since last update.

Ubuntu 16.04 x64 + VsCode + Code Runner で Python3を使ってみる

Last updated at Posted at 2019-01-22

目的

Code Runner のデフォルトの Python2 を Python3 に切り替えてみる
# これでいいのかなぁ・・・
追記 2020/06/22
修正になったバージョンが不明なのだけど 1.46.1 の時点では以下の手順で修正する
・ファイル -> 基本設定 -> 設定
・検索ボックスに Code-runner:Executor Map を入力する


・setting.json で編集をクリックする
 ・修正前
    "code-runner.executorMap": {
    }
 ・修正後
    "code-runner.executorMap": {
        "python": "python3 -u"
    }

VsCodeをインストールする

Download Visual Studio Code
より .deb 64bit をDLする
$ sudo dpkg -i code_1.30.2-1546901646_amd64.deb
以下が追加される
$ ls /etc/apt/*/*
/etc/apt/sources.list.d/vscode.list
/etc/apt/trusted.gpg.d/microsoft.gpg

pylintをインストールする

$ sudo apt install python-pip
$ sudo apt install python3-pip
$ sudo pip3 install pylint

拡張機能の追加

 Japanese Language Pack for VS Code
 Code Runner
 Python for VSCode

Code RunnerでPython3をキックする

codeを起動後
・ファイル -> 基本設定 -> 設定 で Setting を開く
・設定の検索で executorMap を入力する
・ユーザー設定に以下を追加後保存する


    "code-runner.executorMap": {
        "python": "python3 -u"
    }

追記 2020/06/22
修正になったバージョンが不明なのだけど 1.46.1 の時点では以下の手順で修正する
・ファイル -> 基本設定 -> 設定
・検索ボックスに Code-runner:Executor Map を入力する


・setting.json で編集をクリックする
 ・修正前
    "code-runner.executorMap": {
    }
 ・修正後
    "code-runner.executorMap": {
        "python": "python3 -u"
    }

サンプルの実行

test01.py
# _*_ coding: utf-8 _*_
# coding:utf-8 <-- こちらの方が良いようだ??
# Windows Add env PYTHONIOENCODING = UTF-8 & restart vscode
print('日本語')

[Running] python3 -u "/path/to/dev/vscode/python/samp/test01.py"
日本語

[Done] exited with code=0 in 0.05 seconds

# _*_ coding: utf-8 _*_ の有無にかかわらず、正しく実行される

VsCode をランチャーに登録してみる

 ランチャーに常時アイコンを表示したい場合は、アプリケーションを起動した後
 ランチャーのアイコンを右クリックしてLauncherに登録をクリックすれば常時表
 示されるようになります。

参考にしたサイトはこちら

Can't use python3 #366
Ubuntu 16.04 LTSの使い方 (基礎編)

6
4
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
6
4