我正在尝试使用pyenv安装的python 3.6.5版本在RHEL上使用Matplotlib。 (使用以下命令安装)
→ 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
出现以下错误,并发现了许多具有类似问题的问题:
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'
但是,建议的解决方案通常是使用软件包管理器安装tkinter。
但是我尝试安装:
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
每个都已经安装或没有区别(每次安装新软件包时都要重新构建python)。
系统python能够找到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
>>>
所以我不确定如何使用pyenv安装python,并使用相同版本的tkinter?
更新:
发现可以使用$ PYTHON_CONFIGURE_OPTS设置构建配置选项后,我尝试使用指定库的位置(对于linuxbrew下载的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
和(使用系统tcl / tk):
export PYTHON_CONFIGURE_OPTS="--with-tcltk-includes=-I/usr/include --with-tcltk-libs=-L/usr/lib64"
pyenv install 3.6.5
每一个都没有运气。使用以下命令找到系统tcl / tk:
→ 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
最佳答案
以下是我在Ubuntu 19.04和Fedora 29上使用pyenv
1.2.11的分步操作方法:
安装pyenv
使用安装程序
git clone https://github.com/pyenv/pyenv-installer
chmod +x pyenv-installer/bin/pyenv-installer
pyenv-installer/bin/pyenv-installer
用手
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
设置
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
安装依赖
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
浅顶软呢帽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
使用
pyenv
安装Python-3.6.8pyenv install 3.6.8
检查安装
$ pyenv local 3.6.8 # Create file .python-version
$ python --version
Python 3.6.8
安装模块
python -m pip install --user --upgrade pip
python -m pip install --user pipenv
...
pipenv
用法示例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
关于python - RHEL/Pyenv:没有名为“_tkinter”的模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49677522/