24

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

Community
  • 1
  • 1
antonio
  • 10,629
  • 13
  • 68
  • 136
  • Check out WinPython for more things available: https://winpython.github.io/ – Wayne Werner May 24 '17 at 22:38
  • I can't understand what happened here. The question clearly says (and said from the beginning) "assuming we do not have an existing Python installation in the same machine"; but the accepted answer starts "Assuming you are on Windows and you also have a regular Python distribution installed". Why would this answer be acceptable if it's based on a requirement that was explicitly ruled out in the question? – Karl Knechtel Apr 26 '23 at 19:33
  • @KarlKnechtel: Good point. The idea is to produce a Tkinter-enabled zip, and you have to get Tkinter files somewhere, such as an existing distro. Once you have built your zip, you will be able to use Tkinter on a computer where there is no existing distro. The question could be improved with a script, to be run from the embedded Python, downloading the relevant files and placing them in the calling embedded Python. – antonio Apr 26 '23 at 20:38

5 Answers5

26

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\
lucatrv
  • 725
  • 8
  • 14
  • this solution worked for me while working with Robot Editor and embedded python 3.6.5. thanks @lucatrv – Jitendra Jan 26 '19 at 17:05
  • 6
    After copying the files I've got the error: "import _tkinter # If this fails your Python may not be configured for Tk ModuleNotFoundError: No module named '_tkinter'" It appears that I needed to add the line ".\DLLs" to the python36._pth file. I hope this helps anyone that has the issue. – TeaHoney Jul 01 '19 at 04:32
  • 4
    Adding on @TeaHoney s fix, moving the `tkinter` folder to `embedded_distribution_folder\ ` (the root folder) was required – Harald Thomson Dec 10 '19 at 15:23
  • It's helpful for me, thanks @TeaHoney and Harald Thomson. When you get stuck, please reference these two suggestions. – Carson Mar 17 '20 at 10:28
  • The /Lib/tkinter folder MUST be copied to the root. If you copy it to /Lib it will not work. – rlaphoenix Feb 07 '23 at 19:22
1

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
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))
MosGeo
  • 1,012
  • 9
  • 9
0

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

0

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:

  1. To install everything on target systems with shell automation instead (distribution size <1MB)
  2. To create portable version from standard python with just replacing absolute paths to relative (distribution size >> 100MB)

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.

halt9k
  • 527
  • 4
  • 13
0

Some fix to the answer of @lucatrv for python3.11 embeddable.

  • python311 may use ./Lib/site-packages/ but not just ./Lib/, be careful about the folder where your packages are installed
  • If you do not have a DLLs folder, put the files from DLLs to the root folder of python 311
  • tcl can be pasted to the root, while tkinter needs to be pasted into your packages folder
  • When you test, if tkinter is loaded but 'fails', think about the place of DLLs