His Masters' Voices Wiki

よろずのことの書き残し

ユーザ用ツール

サイト用ツール


python:env_ubuntu

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
python:env_ubuntu [2022/07/19 10:11] – [仮想環境へ切り替え] nipa28python:env_ubuntu [2022/07/19 11:03] (現在) – [手順3 VS CodeをPython IDEとして使う] nipa28
行 17: 行 17:
  
  
-操作+手順1 Python仮想環境の導入
 --- ---
  
 参考サイトの写経です。 参考サイトの写経です。
  
-現環境の確認+### 現環境の確認
 ``` ```
 hiroshi@VPCF24AJ-ubuntu:~$ which python3 hiroshi@VPCF24AJ-ubuntu:~$ which python3
行 42: 行 42:
 ``` ```
  
 +### pip、pipenvのインストール
 +
 +<WRAP center round tip 60%>
 +pip は python独自のパッケージ管理ツール
 +pipenv は Python仮想環境を管理するしくみ
 +</WRAP>
  
  
行 87: 行 93:
 ``` ```
  
 +### 仮想環境のインストール
 +
 +pipenvを使ってPython仮想環境を構築する
  
 ``` ```
 +hiroshi@VPCF24AJ-ubuntu:~$ mkdir pipenv1
 +hiroshi@VPCF24AJ-ubuntu:~$ cd pipenv1
 hiroshi@VPCF24AJ-ubuntu:~/pipenv1$ python3 -m pipenv --python python3 install hiroshi@VPCF24AJ-ubuntu:~/pipenv1$ python3 -m pipenv --python python3 install
 /usr/lib/python3/dist-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 0.1.43ubuntu1 is an invalid version and will not be supported in a future release /usr/lib/python3/dist-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 0.1.43ubuntu1 is an invalid version and will not be supported in a future release
行 149: 行 160:
  
 ``` ```
-UbuntuのPython環境からは、ちゃんと分離されているっぽい。+システム(Ubuntu)のPython環境からは、ちゃんと分離されているっぽい。 
 + 
 +<WRAP center round info 60%> 
 +この環境内でpipインストールしたモジュールやライブライは、システムや他の仮想環境のPython環境に一切影響を与えない。 
 +</WRAP> 
 + 
 +仮想環境から抜ける 
 +``` 
 +(pipenv1) hiroshi@VPCF24AJ-ubuntu:~/pipenv1$  
 +(pipenv1) hiroshi@VPCF24AJ-ubuntu:~/pipenv1$ exit 
 +exit 
 +hiroshi@VPCF24AJ-ubuntu:~/pipenv1$ which python 
 +hiroshi@VPCF24AJ-ubuntu:~/pipenv1$ which python3 
 +/usr/bin/python3 
 +hiroshi@VPCF24AJ-ubuntu:~/pipenv1$  
 + 
 +``` 
 + 
 +### まとめ 
 + 
 +仮想環境を作る 
 +``` 
 +mkdir -p <仮想環境へのパス> 
 +cd <仮想環境へのパス> 
 +python3 -m pipenv --python python3 install 
 +``` 
 + 
 +仮想環境に入る 
 +``` 
 +cd <仮想環境へのパス> 
 +python3 -m pipenv shell  
 +``` 
 + 
 +仮想環境から抜ける 
 +``` 
 +exit 
 +``` 
 + 
 +手順2 VS Codeの導入 
 +--- 
 + 
 +IDE(統合開発環境)として Visual Studio Codeをインストールする。 
 + 
 + 
 +### VS Codeインストール 
 + 
 +``` 
 +hiroshi@VPCF24AJ-ubuntu:~/pipenv1$ code 
 +コマンド 'code' が見つかりません。次の方法でインストールできます: 
 +sudo snap install code 
 +hiroshi@VPCF24AJ-ubuntu:~/pipenv1$  
 + 
 +``` 
 +って言われる。 
 +素直に従ってもよいのだろうが、特に理由もなくGUIアプリの「Ubuntu Software」からインストールした。(Snapストア) 
 + 
 +{{:python:pasted:20220719-103511.png}} 
 + 
 +### VS Code起動、日本語化 
 + 
 +Codeを検索してアイコンから起動 
 + 
 +日本語化するかと勝手に聞いてくるのでお願いする。ボタンを押すと再起動されて・・・ 
 +{{:python:pasted:20220719-103916.png}} 
 + 
 +もう日本語化できた。なんか、いたれりつくせり。 
 +{{:python:pasted:20220719-104047.png}} 
 + 
 +### Python拡張機能の導入 
 + 
 +Python拡張機能を検索して、インストール 
 +{{:python:pasted:20220719-104329.png}} 
 + 
 + 
 + 
 +手順3 VS CodeをPython IDEとして使う 
 +--- 
 + 
 +VS Codeを起動 
 + 
 +プロジェクトフォルダを作って開く (`~/pipenv1/testProj`) 
 +{{:python:pasted:20220719-105014.png}} 
 + 
 +プログラムを書く 
 +{{:python:pasted:20220719-105420.png}} 
 + 
 + 
 +実行環境の選択 
 +ステータスバー右下の 「3.10.4 64bit」のあたりをクリック 
 +インタープリターを選択 から PipEnv の仮想環境を選択 
 + 
 +{{:python:pasted:20220719-105707.png}} 
 + 
 +仮想環境に切り替わったことがステータスバーの表示の変化でわかる 
 +{{:python:pasted:20220719-105918.png}}
  
 +プログラムを実行する
 +{{:python:pasted:20220719-110107.png}}
  
 +ウインドウ右下にターミナルが開いて、無事「hello world!!」出力された
 +{{:python:pasted:20220719-110212.png}}
  
python/env_ubuntu.1658193081.txt.gz · 最終更新: 2022/07/19 10:11 by nipa28