Build a Python environment with WSL + Pyenv + Jupyter + VS Code

Introduction

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.

Installation script

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.

Use Jupyter with VS Code

After installing Jupyter with pip, open Jupyter Notebook from VS Code and code while watching the result.

Connect to WSL + install Python extension

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.

python_ext.png

You can now open your Jupyter Notebook in VS Code. You can also change the version with Pyenv. The simple usage is explained below.

Create a new notebook

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".

create_new_note.png

Then a new Notebook will be created. The image is writing Hello world.

jupyter_run.png

Switch environment with Pyenv

The current version of Python is displayed near the bottom left of VS Code, and you can change the version by clicking this.

pyenv_button.png

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.

choose_python.png

in conclusion

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].

Recommended Posts

Build a Python environment with WSL + Pyenv + Jupyter + VS Code
Build a python execution environment with VS Code
Build a python virtual environment with pyenv
How to build Python and Jupyter execution environment with VS Code
Build a python environment with pyenv (OS X El Capitan 10.11.3)
Build a development environment using Jupyter and Flask with Python in Docker (supports both VS Code / code-server)
[Pyenv] Building a python environment with ubuntu 16.04
Build Jupyter Lab (Python) environment with Docker
Build a modern Python environment with Neovim
I tried to build an environment with WSL + Ubuntu + VS Code in a Windows environment
Try to create a python environment with Visual Studio Code & WSL
Create a simple Python development environment with VS Code and Docker
Build jupyter notebook environment with Visual Studio Code (VS Code) Mac version
Build python environment with pyenv on EC2 (ubuntu)
Build Python development environment with Visual Studio Code
Build a python environment with ansible on centos6
[Python] Build a Django development environment with Docker
Create a python3 build environment with Sublime Text3
[Memo] Build a virtual environment with Pyenv + anaconda
Build a simple Python virtual environment without pyenv
Build a virtual environment with pyenv and venv
Use Python in Anaconda environment with VS Code
Quickly build a Python Django environment with IntelliJ
Build a Python machine learning environment with a container
Make your Python environment "easy" with VS Code
Prepare a Python virtual environment for your project with venv with VS Code
I was addicted to creating a Python venv environment with VS Code
Steps to create a Python virtual environment with VS Code on Windows
Python with VS Code (Windows 10)
Build python3 environment with ubuntu 16.04
Debug Python with VS Code
Build python environment with direnv
Build a Python environment offline
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a python environment for each directory with pyenv-virtualenv
Build a Python environment on your Mac using pyenv
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a Python development environment using pyenv on MacOS
Build a numerical calculation environment with pyenv and miniconda3
Python local development environment construction template [Flask / Django / Jupyter with Docker + VS Code]
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
Let's run jupyter natively supported by VS Code with python3.8
Build python virtual environment with virtualenv
Build a Go development environment with VS Code's Remote Containers
Build Mysql + Python environment with docker
Create a virtual environment with Python!
Building a virtual environment with Python 3
Get a clean Python development environment with pyenv + pipx + Poetry
Build a basic Data Science environment (Jupyter, Python, R, Julia, standard library) with Docker.
Build a python3 environment on CentOS7
Install python with mac vs code
Are you still using Jupyter Notebook? Enjoy a comfortable Python life with Jupyter Life (.py) with VS Code ?!
Create a Python environment for professionals in VS Code on Windows
Create a Python execution environment for Windows with VScode + Remote WSL
Build a Python environment on your Mac with Anaconda and PyCharm
Build a Python execution environment using GPU with GCP Compute engine
Create a C ++ and Python execution environment with WSL2 + Docker + VSCode
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
Building a Python3 environment with Amazon Linux2
Easily build a development environment with Laragon
Install Python as a Framework with pyenv