Reputation: 11120
Python embeddable zip comes without pip and Tkinter.
It is easy to install pip with get-pip.py in the embeddable zip.
How can we install Tkinter too (assuming we do not have an existing Python installation in the same machine)?
Upvotes: 25
Views: 15451
Reputation: 1
The Windows embeddable version lacks Tkinter and you must copy it from the regularly installed version.
Lib\tkinter -> embedded_folder
tcl -> embedded_folder
DLLs -> embedded_folder
Modify pythonXX._pth add .\DLLs path for reference
Tested on python 3.12.5 , it works.
Upvotes: 0
Reputation: 1
An extra piece of information for the answer chosen. Edit the ._pth (python312._pth for my python3.12) file, located in the root folder, to indicate to Python where it should look for the extra packages and DLLs used.
python312.zip
my-installed-packages
DDLs
Lib
.
https://docs.python.org/3/library/sys_path_init.html#pth-files
When the file exists, all registry and environment variables are ignored, isolated mode is enabled, and site is not imported unless one line in the file specifies import site. Blank paths and lines starting with # are ignored. Each path may be absolute or relative to the location of the file. Import statements other than to site are not permitted, and arbitrary code cannot be specified.
Upvotes: 0
Reputation: 903
Assuming you are on Windows and you also have a regular Python distribution installed (same version of the embedded distribution), to install Tkinter in the embedded distribution you can copy the following files from the regular Python distribution:
tcl
folder to embedded_distribution_folder\
(root folder of the embedded distribution)tkinter
folder (which is under Lib
) either to embedded_distribution_folder\Lib
or to embedded_distribution_folder\
_tkinter.pyd
tcl86t.dll
tk86t.dll
zlib1.dll
(which are under DLLs
, zlib1.dll
for python >= 3.12) either to embedded_distribution_folder\DLLs
or to embedded_distribution_folder\
Upvotes: 34
Reputation: 11
Some fix to the answer of @lucatrv for python3.11 embeddable.
Upvotes: 1
Reputation: 1908
Adding to @lucatrv answer and @TeaHoney comment, it is possible to add the folders to the path from the code. Here is a general code that should work for the following tree structure for the python directory
import sys
from pathlib import Path
python_path = Path(sys.exec_prefix)
dlls_path = Path(python_path, "DLLs")
tcl_path = Path(python_path, "tcl")
sys.path.insert(0, str(dlls_path))
sys.path.insert(0, str(tcl_path))
Upvotes: 1
Reputation: 955
It's probably correct to emphasize that this question is not only about embeddable=portable python, but also about portable environment?
After trying embeddable for distribution and having some difficulties adding Tkinter and other packages, I've found two alternatives to be considered:
If you distribute on Windows and all open-source, here is PowerShell experiment which solves both 1 and 2 cases. Exact goals were not specified in this question, in my case one of goals was to make python script to be available to novice users who can't install python environment, and another goal was to make easy portable deploy for VM's.
Upvotes: 0
Reputation: 11
Use the windows python set up installer From python.org. Then custom install tkinter only in a custom directory. If you are planning to make a deployable application. Make sure the set environment variables checkbox variable is disabled
Upvotes: 0