安装NVIDIA及CUDA驱动后Python3.5报_tkinter模块缺失错误
Hey Jonny, let's work through this _tkinter error you're hitting with Python 3.5 after setting up NVIDIA and CUDA drivers. Since you noted python3-tk is already up-to-date and Python 3.6 is installed alongside, the issue is likely tied to Python 3.5's tkinter association or environment interference from CUDA. Here are actionable steps to fix this:
First, confirm your Python 3.5 installation's tkinter status
Run these commands to narrow down if the problem is specific to your Python 3.5 build:# Get the full path of your Python 3.5 executable which python3.5 # Test if tkinter loads with this Python version python3.5 -c "import tkinter; print(tkinter.__file__)"If this throws the same error, your Python 3.5's tkinter module is either missing or broken—note that the default
python3-tkpackage is often linked to your system's primary Python version (which is 3.6 in your case).Install Python 3.5-specific tkinter package
On Ubuntu/Debian systems, version-specific tkinter packages exist for alternative Python releases. Try installing the one for Python 3.5:sudo apt-get install python3.5-tkIf you get a "package not found" error, add the
deadsnakesPPA (which maintains older Python versions) first:sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get update sudo apt-get install python3.5-tkCheck if CUDA's environment variables are breaking dependencies
CUDA installation often modifiesLD_LIBRARY_PATH, which can override system libraries that tkinter relies on. Test this by temporarily unsetting the variable:unset LD_LIBRARY_PATH && python3.5 -c "import tkinter"If this works, adjust your environment to prioritize system libraries. Edit your
~/.bashrcor~/.profilefile and add this line (ensuring system paths come first):export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATHReload your profile with
source ~/.bashrcto apply the change.Reinstall Python 3.5 and its tkinter module
If corruption is the issue, reinstall Python 3.5 to fix broken files:sudo apt-get reinstall python3.5 python3.5-tkIf you compiled Python 3.5 from source originally, recompile it with tkinter support. First install required dependencies:
sudo apt-get install tk-dev tcl-devThen re-run the configure step with tk/tcl flags before compiling:
./configure --with-tk --with-tcl make && sudo make installVerify virtual environment settings
If you're using a virtual environment for Python 3.5, it might be isolated from system-wide tkinter. Create a new environment with system site-packages enabled to test:python3.5 -m venv --system-site-packages my_fixed_env source my_fixed_env/bin/activate python -c "import tkinter"If this works, you can either switch to this environment or copy the tkinter files from your system Python 3.5's site-packages to your existing virtual environment.
内容的提问来源于stack exchange,提问作者Jonny

