With the recent AI boom such as deep learning, it was hard for me to spend time while building a Python environment and putting in the necessary packages ... But) I started trying to automate it in a script, so I will summarize it. I hope it will be helpful in shortening the time required to build an environment.
In this article, I will introduce a Python environment that can be casually created and destroyed without polluting the system environment with pyenv [^ 1] and pyenv-virtualenv [^ 2], and put the necessary packages with pip in it. I will. It also uses VS Code's Python extension to allow you to run Python in the form of a Jupyter Notebook. All of these environments are built on Ubuntu running on Windows Subsystem for Linux for Windows.
I created a script to build the environment. The script is uploaded to GitHub. Issues etc. are welcome.
This script takes the name of the python environment (created with pyenv-virtualenv) as an argument, so execute it as follows.
./setup_env.sh env_name
If you do not add env_name, it will end with an error. Also, apt will install some necessary packages, so you will be asked for the root password on the way. Let's wait for a while until it finishes.
The following packages are also installed with pip. I haven't confirmed all the operations, so it may not work well ...
When complete, pyenv-virtualenv creates a new python environment and applies it (pyenv global env_name is done). In addition, in order to use pyenv, the setting will be added to ~ / .bashrc.
After installing Jupyter with pip, open Jupyter Notebook from VS Code and code while watching the result.
First, connect to WSL with Remote Development. Press the button marked "> <" ← at the bottom left of VS Code to connect to WSL. Regarding Remote Development, I'm sorry for the miso in the foreground, but I would appreciate it if you could refer to it as it is summarized in another article [^ 3].
[^ 3]: Try using VS Code's Remote Development
Then install the extension Python.
You can now open your Jupyter Notebook in VS Code. You can also change the version with Pyenv. The simple usage is explained below.
Open the command palette with cmd + shift + p in VSCode, enter "jupyter" and some commands will appear, so select "Python: Create New Blank Jupyter Notebook".
Then a new Notebook will be created. The image is writing Hello world.
The current version of Python is displayed near the bottom left of VS Code, and you can change the version by clicking this.
You can select the Python environment you want to use from the list. When using Jupyter Notebook, select the environment where jupyter is installed with pip.
I tried to summarize how to set up a Python environment with Pyenv + Jupyter + VS Code. For programming such as deep learning, you can install what you want to use, such as Pytorch [^ 4].