When I tried to use Python on WSL (windows subsystem for linux), it got stuck in Jupyter (solved)

[Caution] I don't think this article is useful if you are not working with root privileges. This issue is caused by working with root privileges, so general users do not need to read it. I think.

I usually develop on WSl, but I will explain the point that I got stuck when I tried to write Python for the first time in a while today.

Operating environment

I'm using pyenv for python version control. I'm also using pipenv to set up a virtual environment in the project directory. I try to install external modules via pipenv.

Environment

Prepare the virtual environment with the following command

mkdir py_playground && cd py_playground
pipenv --python 3.8

Installed external module

Initial directory structure

Pipfile(Node.package in js.Something like json)
Pipfile.lock

Where did you get stuck

I always thought that I would launch vscode and write in Jupyter Notebook, and when I launched a new notebook ...

** Kernel does not connect **

It's funny, the virtual environment should be set up with pipenv ... So I embarked on a long, long journey to launch Jupyter

Problem 1 The .venv directory is not generated by default

It worked when I was developing on windows ... what's the difference ... The first thing I found was that the .venv directory that should contain the interpreter wasn't created. This is because the virtual environment is created under ~ / .local / share / virtualenvs / with the default settings of pipenv. I decided to change this for the time being.

I wrote in .zshrc as follows with reference to Use virtual environment in any place with pipenv (Bash people write in .bashrc) Please give me)

~/.zshrc


export PIPENV_VENV_IN_PROJECT=1

Now the .venv directory is created directly under the project directory. But I haven't been able to connect yet.

Problem 2 Let's try to launch jupyter from the terminal

jupyter lab

Then I got an error. Apparently it is not recommended to run with root privileges, in which case you should add --allow-root

jupyter lab --allow-root

But this time nothing is displayed. I searched for various results, and after creating a configuration file, it was displayed well.

jupyter notebook --generate-config

The following was added to the beginning of the generated setting script.

~/.jupyter/jupyter_notebook_config.py


c = get_config()
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8080

The connection status is now displayed on the OK terminal.

Problem 3 (This is the solution) It doesn't work if the settings of the jupyter system of vscode are left as default.

Apparently, when you start jupyter with vscode, it seems that you start jupyter server at that timing. Problem 2 gets in the way. So I set --allow-root in vscode. Press F1-> type "python jupyter arg" in the search field and you should see python: specify jupyter commandline argument at the beginning. Select it and type --allow-root.

This finally solved it.

Congratulations

Recommended Posts

When I tried to use Python on WSL (windows subsystem for linux), it got stuck in Jupyter (solved)
When I tried to introduce python3 to atom, I got stuck
I want to use Python in the environment of pyenv + pipenv on Windows 10
I referred to it when I got stuck in the django geodjango tutorial (editing)
When Windows Subsystem for Linux (WSL) cannot be started
I got stuck when trying to specify a relative path with relative_to () in python
[Python] When I tried to use matplotlib for graph drawing, I got the error "this application failed to start because it could not find or load the qt platform plugin" windows "".
Use Linux on Windows 10 (WSL2)
When I made CaboCha usable with python3, I got stuck (Windows 10)
How to set up Ubuntu for Windows Subsystem for Linux 2 (WSL2)
What I got stuck around GUI in WSL python environment
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
pykintone on Windows Subsystem for Linux
processing to use notMNIST data in Python (and tried to classify it)
I tried to implement permutation in Python
When I tried to run Python, it was skipped to the Microsoft Store
I tried to implement PLSA in Python 2
I want to use Linux on mac
WSL2 (Windows Subsystem for Linux) installation procedure
I tried to implement ADALINE in Python
I tried to install Docker on Windows 10 Home but it didn't work
A memorandum because I stumbled on trying to use MeCab in Python
I tried using NVDashboard (for those who use GPU in jupyter environment)
Add words to MeCab's user dictionary on Ubuntu for use in Python
I stumbled on the character code when converting CSV to JSON in Python
What I did when I got stuck in the time limit with lambda python
Things to keep in mind when using Python for those who use MATLAB
I tried to implement what seems to be a Windows snipping tool in Python
I tried to use Twitter Scraper on AWS Lambda and it didn't work.
When I try matplotlib in Python, it says'cairo.Context'
I tried to implement TOPIC MODEL in Python
[Question] What happens when I use% in python?
I tried to implement selection sort in python
When I tried to create a project using Python on Docker with PyCharm, it didn't work, but it worked with Docker Compose.
[Python] I want to use only index when looping a list with a for statement
I tried to build an environment with WSL + Ubuntu + VS Code in a Windows environment
A story that got stuck when trying to upgrade the Python version on GCE
[For beginners in competition professionals] I tried to solve 40 AOJ "ITP I" questions with python
[python] When pipenv install of WSL, python on Windows side is called for some reason
I tried to graph the packages installed in Python
[For beginners] How to use say command in python!
I tried to summarize how to use matplotlib of python
I tried Python on Mac for the first time.
I tried to implement Minesweeper on terminal with python
I tried to implement a pseudo pachislot in Python
I tried python on heroku for the first time
I tried to implement Dragon Quest poker in Python
I tried to implement GA (genetic algorithm) in Python
I want to use OpenJDK 11 on Ubuntu Linux 18.04 LTS / 18.10
How to use jupyter lab in Windows 10 local environment
I was able to repeat it in Python: lambda
I want to do something in Python when I finish
How to set up WSL2 on Windows 10 and create a study environment for Linux commands
When I tried to install PIL and matplotlib in a virtualenv environment, I was addicted to it.
Linux (WSL) on Windows
When I tried to build a Rails environment on WSL2 (Ubuntu 20.04LTS), I stumbled and fell.
When I installed python on macOS and used it, I got an error when I put an https connection
Use Heroku in python to notify Slack when a specific word is muttered on Twitter
When I got a list of study sessions in Python, I found something I wanted to make
All up to 775/664, 777/666, 755/644, etc.
How to set up Ubuntu for Windows Subsystem for Linux 2 (WSL2)
I tried to create API list.csv in Python from swagger.yaml