0
1

More than 1 year has passed since last update.

仮想環境を作成してローカルでcolaboratoryを使用する方法

Posted at

googleのcolaboratoryを使用するときに、グーグルのサーバーでなく、ローカルのパソコンをサーバーとして使用したい時がある。その際、さまざまなモジュールをインストールすることがあるが、ローカルの環境を汚染したくないときにvenvを使用する。

以下は忘備録である。

手法

1.仮想環境の作成

以下はmyenvという名前で仮想環境を作成している。

python -m venv myenv

2. 仮想環境内に入る

myenv\Scripts\Activate.ps1

3. モジュールのインストール

pip install jupyter_http_over_ws

4. Jupyter ノートブックの起動

以下のコマンドを入力する。

jupyter notebook --NotebookApp.allow_origin='https://colab.research.google.com' --port=8888 --NotebookApp.port_retries=0

そして以下のhttp://127.0.0.1:8888/tree?toke=...をコピーする。

 Or copy and paste one of these URLs:
        http://localhost:8888/tree?token=何らかの文字列
        http://127.0.0.1:8888/tree?token=何らかの文字列

5.Colab からの接続

colabの接続ボタンをクリックし、「ローカルランタイムに接続」ボタンをクリックする。そして出現したウィンドウに先ほどコピーしたURLを張り付ける。

仮想環境に入るときに「このシステムではスクリプトの実行が無効になっているため、ファイル...」のエラーが出るとき

以下の記事を参考に、powershellを起動し必要なコマンドを入力する。

参考文献

0
1
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
0
1