$python-c"import os as _; print(_.__file__)"/usr/lib64/python3.6/os.py$python-c"import setuptools as _; print(_.__path__)"['/usr/lib/python3.6/site-packages/setuptools']
>>> import tkinter
>>> tkinter.TclVersion, tkinter.TkVersion
(8.5, 8.5)
>>> tkinter._tester()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tkinter' has no attribute '_tester'
>>> tkinter._test()
macOS 11 or later required !
Abort trap: 6
Python may not be configured for Tk
$ python
Python 3.10.4 (main, Apr 26 2022, 19:42:59) [Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter as tk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python@3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 37, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
solution
$ brew info python@3.10
python@3.10: stable 3.10.4 (bottled) [keg-only]
... ...
tkinter is no longer included with this formula, but it is available separately:
brew install python-tk@3.10
... ...
$ brew install python-tk@3.10
==> Downloading https://ghcr.io/v2/homebrew/core/python-tk/3.10/manifests/3.10.4
######################################################################## 100.0% ==> Downloading https://ghcr.io/v2/homebrew/core/python-tk/3.10/blobs/sha256:6a937be1fd531589ef7f9b4d971cb91ee7549d99f7f1aaf97f0fc3c0911f1c5d ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:6a937be1fd531589ef7f9b4d971cb91ee7549d99f7f1aaf97f0fc3c0911f1c5d?s ######################################################################## 100.0% ==> Pouring python-tk@3.10--3.10.4.monterey.bottle.tar.gz ==> Caveats python-tk@3.10 is keg-only, which means it was not symlinked into /usr/local, because this is an alternate version of another formula.
==> Summary ☕️ 🐸 /usr/local/Cellar/python-tk@3.10/3.10.4: 5 files, 132.6KB ==> Running brew cleanup python-tk@3.10... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see man brew).
$ brew reinstall python@3.10 ... ...
## venv
> [!NOTE|label:references:]
> - [12. Virtual Environments and Packages](https://docs.python.org/3/tutorial/venv.html) | [zh-cn](https://docs.python.org/zh-cn/3/tutorial/venv.html)
### PS1
> [!NOTE|label:references:]
> - [How do I change the default virtualenv prompt?](https://stackoverflow.com/a/20026992/2940319)
> - [Python venv module cannot add virtual environment name to PS1, when using PROMPT_COMMAND?](https://stackoverflow.com/a/61682159/2940319)
```bash
$ export VIRTUAL_ENV_DISABLE_PROMPT=1
$ function _venv_info() {
local printf_format=' [%s]'
local venv=''
[[ $# -eq 1 ]] && printf_format="$1"
[[ -n "${VIRTUAL_ENV}" ]] && venv="${VIRTUAL_ENV##*/}"
if [[ -n "${venv}" ]]; then
# shellcheck disable=SC2059
printf -- "${printf_format}" "${venv}"
fi
}
# usage
$ _venv_info "--%s--"
--rmk--
$ _venv_info "(\033[38;5;6;3m%s\033[0m)"
(rmk)
or using PROMPT_COMMAND
$ cat ~/.bashrc
# for venv info
function _venv_info() {
local printf_format=' [%s]'
local venv=''
[[ $# -eq 1 ]] && printf_format="$1"
[[ -n "${VIRTUAL_ENV}" ]] && venv="${VIRTUAL_ENV##*/}"
if [[ -n "${venv}" ]]; then
# shellcheck disable=SC2059
printf -- "${printf_format}" "${venv}"
fi
}
export VIRTUAL_ENV_DISABLE_PROMPT=1
COL_SD_PURPLE='\[\033[38;5;98;3m\]'
COL_SD_GREEN='\[\033[32;2m\]'
COL_NONE='\[\033[0m\]'
COL_DEFAULT="\[\033[38;5;240m\]"
COL_RESET='\[\033[1m\]'
PS1="\\n${COL_RESET}${COL_DEFAULT}(\\u@\\h${COL_RESET} \\w${COL_RESET}${COL_DEFAULT}) "
PS1+="\$(__git_ps1 \"- (${COL_SD_GREEN}%s${COL_NONE}${COL_DEFAULT}) \")"
PS1+="\$(_venv_info \"- (${COL_SD_PURPLE}%s${COL_NONE}${COL_DEFAULT}) \")"
PS1+="\\$ ${COL_NONE}"
export PS1
$ pip config -v list
For variant 'global', will try loading '/Library/Application Support/pip/pip.conf'
For variant 'user', will try loading '/Users/marslo/.pip/pip.conf'
For variant 'user', will try loading '/Users/marslo/.config/pip/pip.conf'
For variant 'site', will try loading '/Users/marslo/.venv/rmk/pip.conf'