Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python embeddable zip: install Tkinter

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)?

like image 667
antonio Avatar asked Jun 08 '16 18:06

antonio


People also ask

Can I PIP install Tkinter?

Tkinter can be installed using pip. The following command is run in the command prompt to install Tkinter. This command will start downloading and installing packages related to the Tkinter library. Once done, the message of successful installation will be displayed.

What is embeddable zip file?

The embeddable package. New in version 3.5. The embedded distribution is a ZIP file containing a minimal Python environment. It is intended for acting as part of another application, rather than being directly accessed by end-users.


2 Answers

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\
  • files _tkinter.pyd tcl86t.dll tk86t.dll (which are under DLLs) either to embedded_distribution_folder\DLLs or to embedded_distribution_folder\
like image 98
lucatrv Avatar answered Oct 20 '22 07:10

lucatrv


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

  • DLLs
  • tcl
  • python.exe
import sys
from pathlib import Path
pytohn_path = Path(sys.exec_prefix)
dlls_path = Path(pytohn_path, "DLLs")
tcl_path = Path(pytohn_path, "tcl")
sys.path.insert(0, str(dlls_path))
sys.path.insert(0, str(tcl_path))
like image 1
MosGeo Avatar answered Oct 20 '22 06:10

MosGeo