web-dev-qa-db-ja.com

python3.4.2用にtkinterを構成します

最近、最新のpython3.Xのインストール中に問題が発生しました。
Python-3.4.2.tar.xzpython.orgパッケージを使用してインストールしました。その後、tkinterモジュールのインポートを試みましたが、成功しませんでした。

import tkinterの出力は次のとおりです。

[。 python3.4/tkinter/__ init __。py "、38行目、
 import _tkinter#これが失敗した場合、PythonがTk 
 ImportErrorに設定されていない可能性があります:モジュールが指定されていません'_tkinter' 

私は次の解決策も試しました:

しかし、それらのどれも助けなかった。
これらの解決策を試しているときに、エラーが次のようになっていることに気づいた場合:

import _tkinter#これが失敗した場合、PythonはTk用に設定されていない可能性があります

それから私はそれについてグーグルで見つけた this
を読むTkinterのサポートセクションを確認すると、Step 1が失敗し、この行でスタックしました

Tcl/Tkをデフォルトの場所にインストールする場合、単に「make」を再実行すると_tkinter拡張機能がビルドされます。

上記の行に関して、私の質問は次のとおりです。
makeコマンドを実行するmakeファイルはどこにありますか?

そして、Python [3.4.2]が受け入れるようにtkinterを設定するにはどうすればよいですか?


編集:

言及するのを忘れましたが、import tkinterはUbuntu 14.04.1のPythonのデフォルトのインストール(Python-3.4.0)で動作します

5
devGeek

_tkinterモジュールを使用してソースからpython3.4.2をビルドするには、次のビルド依存関係をインストールする必要があります。

Sudo apt-get install tk8.6-dev

_tkinterファイルがtk/tclヘッダーを自動的に検出してモジュールを作成するため、makeを再度実行してsetup.pyサポートを追加するだけです。

~/Downloads/Python-3.4.2$ make
running build
running build_ext
building '_tkinter' extension
gcc -pthread -fPIC -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Werror=declaration-after-statement -DWITH_APPINIT=1 -I/usr/include/tcl8.6 -I/usr/X11/include -I./Include -I. -IInclude -I/usr/include/x86_64-linux-gnu -I/usr/local/include -I/home/sylvain/Downloads/Python-3.4.2/Include -I/home/sylvain/Downloads/Python-3.4.2 -c /home/sylvain/Downloads/Python-3.4.2/Modules/_tkinter.c -o build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/_tkinter.o
gcc -pthread -fPIC -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Werror=declaration-after-statement -DWITH_APPINIT=1 -I/usr/include/tcl8.6 -I/usr/X11/include -I./Include -I. -IInclude -I/usr/include/x86_64-linux-gnu -I/usr/local/include -I/home/sylvain/Downloads/Python-3.4.2/Include -I/home/sylvain/Downloads/Python-3.4.2 -c /home/sylvain/Downloads/Python-3.4.2/Modules/tkappinit.c -o build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/tkappinit.o
gcc -pthread -shared build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/_tkinter.o build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/tkappinit.o -L/usr/X11/lib -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib -ltk8.6 -ltcl8.6 -lX11 -o build/lib.linux-x86_64-3.4/_tkinter.cpython-34m.so

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2                  _dbm                  _gdbm              
_lzma                 _sqlite3                                 
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
[...]

これで、python3.4.2でtkinterをインポートできます。

~/Downloads/Python-3.4.2$ ./python 
Python 3.4.2 (default, Oct 30 2014, 11:34:17) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> 

元の答え:

Python3.4.2が本当に必要でない限り、14.04でデフォルトのpython3バージョンを使用します( .4.

あとは、次のパッケージをインストールするだけです。

Sudo apt-get install python3-tk tk

そして、この方法でpythonインタープリターを開始します。

/usr/bin/python3

それ以外の場合は、/usr/local(3.4.2)にインストールしたバージョンを常に取得します。

Python3でtkをインポートすることで動作するはずです:

$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> 
8
Sylvain Pineau

Matplotlibにのみtkinterが必要な場合は、Eggのような別のバックエンドを使用することもできます:matplotlibをmplとしてインポートmpl.use( 'Agg')

詳細を見る こちら

0
Noam Peled
Sudo apt-get install python3-tk tk  

pyenv install 3.5.0  

それでおしまい

0
user610433

ご存知のとおり、私はUbuntu 16.04を使用しています。最初の回答に追加すると、pythonファイルから次のことが行われます(抽出後):

./configure #(there will be a configure file)
make
make test
Sudo make install

私はこれらのことを初めてしましたが、それでも私にこれらのエラーを見せていました:

IDLE can't import Tkinter.  Your Python may not be configured for Tk.

cmdからpython3 -m idlelib.idleを実行中。

だから私はやった:

Sudo apt-get install tk-dev

またはあなたができる

Sudo apt-get install tk8.6-dev

また

./configure
make
make test
Sudo make install

次回python3 -m idlelib.idleを実行したときに問題が解決し、IDLEが開かれました。

0
Pushkaraj Joshi