How to prepare the execution environment of the ultra-lightweight Python "Python embeddable" (about 15MB) Memo (until the introduction of pip and other libraries (eg psutil))

Ultra-lightweight Python "** Python embeddable **". An ultra-lightweight Python execution environment of about 8MB for download compressed file .zip and about 16MB for decompression. I was able to confirm how to prepare the execution environment, so make a note of it.

  1. Download the Windows ** embeddable ** package (64-bit). (python-3.9.1-** embed **-amd64.zip)
  2. After unpacking, pass the .py file to "python.exe" inside and execute it. (DOS command: python.exe sample.py)
  3. ** Only the Python standard library ** can be used, so to install other libraries, ** First ** Install "** pip ". Download destination: Download " get-pip.py **" from https://bootstrap.pypa.io/get-pip.py, drag "get-pip.py" onto "python.exe" & drop.
  4. Open the file "** python39._pth **" with a text editor and remove the comment from "#import site" to "import site".
  5. For example, to install the library "psutil" that obtains information such as CPU and memory usage, "DOS command: ** python.exe -m pip install psutil **"
  6. OK

Details

https://www.python.org/downloads/windows/ image.png  ↓ https://www.python.org/downloads/release/python-391/ Download the Windows embeddable package (64-bit). image.png  ↓ python-3.9.1-embed-amd64.zip image.png  ↓ When expanded, the folder "python-3.9.1-embed-amd64" will contain image.png Mostly composed of .pyd (contents are DLL) and .dll files. image.png  ↓ When you start "python.exe" inside, the interactive console is displayed. image.png image.png

import datetime
datetime.datetime.now()
x = 2**32
x

↓ Download destination: Download "get-pip.py" from https://bootstrap.pypa.io/get-pip.py, save it in the folder "python-3.9.1-embed-amd64", and "get-pip" Drag and drop ".py" onto "python.exe" (or DOS command: python.exe get-pip.py) and execute. image.png image.png "Pip" is available.  ↓ Open the file "python39._pth" with a text editor and uncomment "#import site" "import site" image.png image.png  ↓ For example, if you install the library "psutil" that obtains information such as CPU and memory usage, you can use "DOS command: python.exe -m pip install psutil". image.png  ↓ image.png Installation is complete.  ↓ When I try to use the library "psutil", image.png CPU usage rate and memory usage rate are acquired and OK.

import psutil
psutil.cpu_percent()
psutil.virtual_memory()

↓ When the library "psutil" is installed, the execution environment is about 34MB. image.png

reference

https://qiita.com/mm_sys/items/1fd3a50a930dac3db299 https://qiita.com/suzuki_y/items/3261ffa9b67410803443 https://pypi.org/project/psutil/

Recommended Posts

How to prepare the execution environment of the ultra-lightweight Python "Python embeddable" (about 15MB) Memo (until the introduction of pip and other libraries (eg psutil))
Introduction to Python Let's prepare the development environment
Prepare the execution environment of Python3 with Docker
[Python] Chapter 01-02 About Python (Execution and installation of development environment)
Python environment construction and SQL execution example to DB and memo of basic processing for statistics 2019
I want to know the features of Python and pip
Overview of Python virtual environment and how to create it
[Introduction to Python] I compared the naming conventions of C # and Python.
[Python] How to get the first and last days of the month
[Introduction to Python] How to use the Boolean operator (and ・ or ・ not)
How to build Python and Jupyter execution environment with VS Code
[Python] How to specify the window display position and size of matplotlib
[Introduction to Python] How to sort the contents of a list efficiently with list sort
[Introduction to Data Scientists] Basics of scientific calculation, data processing, and how to use the graph drawing library ♬ Environment construction
Prepare a development environment that is portable and easy to duplicate without polluting the environment with Python embeddable (Windows)
About the virtual environment of python version 3.7
How to prepare Python development environment [Mac]
How to pass the execution result of a shell command in a list in Python
How to make VS Code aware of the venv environment and its benefits
Build a python environment to learn the theory and implementation of deep learning
[Introduction to Python] How to get the index of data with a for statement
[Introduction to statistics] What kind of distribution is the t distribution, chi-square distribution, and F distribution? A little summary of how to use [python]
Introduction to Python "Re" 1 Building an execution environment
About the * (asterisk) argument of python (and itertools.starmap)
From the introduction of pyethapp to the execution of contract
How to execute a schedule by specifying the Python time zone and execution frequency
[Python] How to calculate the approximation formula of the same intercept 0 as Excel [scikit-learn] Memo
[Introduction to Sound] Let's arrange the introduction to sounds of python and R ♬-Listen to the sound of the explosion of Nikkei 255-
[Python environment maintenance] De-NeoBundle. Prepare the environment of the super convenient complementary plug-in jedi-vim with dein and set it to be comfortable