Reputation: 155
I'm trying to use Matplotlib on RHEL using a pyenv installed version of python 3.6.5. (installed using the following command)
→ pyenv install 3.6.5
Installing Python-3.6.5...
python-build: use readline from homebrew
Installed Python-3.6.5 to /home/swp1g17/.pyenv/versions/3.6.5
→ pyenv global 3.6.5
I'm presented with the following error, and have found many questions that have a similar issue:
Python 3.6.5 (default, Apr 5 2018, 17:22:36)
[GCC 5.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/swp1g17/.pyenv/versions/3.6.5/lib/python3.6/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
However the suggested solution is usually to install tkinter using a package manager. However I've tried installing:
2872 sudo yum install rh-python36-python-tkinter
2873 sudo yum install rh-python35-python-tkinter
2874 sudo yum install rh-python34-python-tkinter
2891 sudo yum install tkinter
2893 sudo yum install python36-tkinter
2902 sudo yum install gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel gdbm-devel ncurses-devel gl..
2916 sudo yum install tkinter.x86_64 rh-python36-python-tkinter.x86_64 rh-python35-python-tkinter.x86_64 rh-python34-python-tkinter.x86_64 p..
2921 sudo yum install tcl
2933 sudo yum install tk-devel
2934 sudo yum install tk
3000 sudo yum install tkinter
3026 sudo yum install tix
3031 sudo yum install tk
3032 sudo yum install tk-devel
> 3033 sudo yum install tcl-devel
with each already having been installed or making no difference (having rebuilt python each time a new package was installed.
The system python is able to locate tkinter:
→ /usr/bin/python3.6
Python 3.6.3 (default, Jan 4 2018, 16:40:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
so I'm unsure how to install python using pyenv and have it use the same version of tkinter?
UPDATE: Having found that build configuration options can be set using $PYTHON_CONFIGURE_OPTS I've tried specifying the library locations using (for linuxbrew downloaded tcl/tk):
export PYTHON_CONFIGURE_OPTS="--with-tcltk-includes=-I/home/linuxbrew/.linuxbrew/opt/tcl-tk/include --with-tcltk-libs=-L/home/linuxbrew/.linuxbrew/opt/tcl-tk/lib"
pyenv install 3.6.5
and (using system tcl/tk):
export PYTHON_CONFIGURE_OPTS="--with-tcltk-includes=-I/usr/include --with-tcltk-libs=-L/usr/lib64"
pyenv install 3.6.5
each with no luck. System tcl/tk was found using:
→ whereis tcl
tcl: /usr/lib64/tcl8.5 /usr/include/tcl.h /usr/share/tcl8.5
→ whereis tcl
tcl: /usr/lib64/tcl8.5 /usr/include/tcl.h /usr/share/tcl8.5
Upvotes: 6
Views: 3712
Reputation: 54551
Below is my step-by-step howto using pyenv
1.2.11 on Ubuntu 19.04 and Fedora 29:
Install pyenv
Using the installer
git clone https://github.com/pyenv/pyenv-installer
chmod +x pyenv-installer/bin/pyenv-installer
pyenv-installer/bin/pyenv-installer
By hand
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
Setup pyenv
$ cat >> ~/.bashrc
# Load pyenv automatically
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
Ctrl + D
$ source ~/.bashrc
$ pyenv --version
pyenv 1.2.11-8-g070e1c85
Install dependencies
Ubuntu 19.04 Disco Dingo
sudo apt install tk-dev # <-- This has fixed my issue
sudo apt install libbz2-dev
sudo apt install libreadline-dev
sudo apt install libsqlite3-dev
Fedora 29
sudo dnf install tk-devel # <-- This may fix your issue
sudo dnf install libbz2-dev
sudo dnf install readline-devel
sudo dnf install libsqlite3x-devel
sudo dnf install openssl-devel
sudo dnf install make
Install Python-3.6.8 using pyenv
pyenv install 3.6.8
Check installation
$ pyenv local 3.6.8 # Create file .python-version
$ python --version
Python 3.6.8
Install modules
python -m pip install --user --upgrade pip
python -m pip install --user pipenv
...
Example of pipenv
usage
cd /path/where/your/Pipfile/is/located/
pyenv local 3.6.8
python -m pipenv --rm # first time: No virtualenv has been created...
python -m pipenv update --dev
python -m pipenv run python -m nose # my unit tests
Upvotes: 3