[PYTHON] [Note] Running a virtual environment on Jupyter Notebook [ImportError: There is no module called win32api]

Preface

It was yesterday that I wanted to do various things with PyGame. Today, I was working on creating a virtual environment so that I could try it on Jupyter Notebook, but I was a little addicted to it.

Here, I will leave the symptom and the remedy as a memo. It seems that not many people have the same symptoms, but I hope it helps.

environment

Windows 10 Python 3.8 conda 4.9.0

Premise

It is assumed that the contents introduced in Settings for easy selection of multiple kernels in Jupyter are over.

Symptoms and remedies

I thought that the kernel settings were completed, so I immediately entered the virtual environment and started Jupyter Notebook from there, and I got a kernel error.

When I read the message, it said, "I can't import win32api."

If you look at some articles, you will find the following sites. [ImportError: There is no module called win32api](https://www.it-swarm-ja.tech/ja/python/importerror%EF%BC%9Awin32api%E3%81%A8%E3%81%84%E3% 81% 86% E3% 83% A2% E3% 82% B8% E3% 83% A5% E3% 83% BC% E3% 83% AB% E3% 81% AF% E3% 81% 82% E3% 82% 8A% E3% 81% BE% E3% 81% 9B% E3% 82% 93/1043946510 /)

Pypiwin32 seems to be old, so I installed pywin32 with pip instead, but it still doesn't work. If you read further,

Must be run according to pywin32 github

The words. When I went to see github immediately,

Note that if you want to use pywin32 for "system wide" features, such as registering COM objects or implementing Windows Services, then you must run the following command from an elevated command prompt:

python Scripts/pywin32_postinstall.py -install

I don't know about half of it, but if you want to use it system-wide (cross-cutting?), You have to register with the Windows service, so I went to the Scripts storage (in my case, directly under the Anaconda3 file) and specified it. When I ran the command, it finally worked.

Miscellaneous thoughts

I created a virtual environment that can also use Jupyter Notebook before, but I don't remember getting stuck in such a swamp at that time.

Probably, the Python version at that time was 3.6 or 3.5, but this time it may be because it was specified by Pygame and 3.8 was installed when creating the virtual environment.

Summary

Thank you for collective intelligence.

Recommended Posts

[Note] Running a virtual environment on Jupyter Notebook [ImportError: There is no module called win32api]
Error running Jupyter Notebook in Anaconda virtual environment
A note on how to load a virtual environment in PyCharm
I want to use a virtual environment with jupyter notebook!
A note when I can't open Jupyter Notebook on Windows
Try running Jupyter Notebook on Mac
Make Jupyter Notebook a service on CentOS
Creating a python virtual environment on Windows
Run Jupyter notebook on a remote server
Install and set Jupyter Notebook to create a study note creation environment [Mac]
Build a PYNQ environment on Ultra96 V2 and log in to Jupyter Notebook
Python virtual environment in 2021 ~ There is no reason not to use venv now ~
Try using conda virtual environment with Jupyter Notebook
Simply display a line graph on Jupyter Notebook
[Venv] Create a python virtual environment on Ubuntu
Create a Python virtual development environment on Windows
How to build a Python virtual execution environment using Visual Studio Code and pipenv on a Windows machine (also Jupyter notebook)