2017-10-06 48 views
0

我在我的python 3 docker容器中遇到了tk问题。为什么conda安装tk不能在我的Docker容器中工作,即使它说它安装了?

我想:

conda install tk 

,但它说,它没有安装它

[email protected]:/home_simulation_research/overparametrized_experiments/pytorch_experiments# conda install tk 
Fetching package metadata ........... 
Solving package specifications: . 

# All requested packages already installed. 
# packages in environment at /opt/conda: 
# 
tk      8.6.7    h5979e9b_1 

,但是当我去到Python,并尝试将其导入它不起作用:

>>> import Tkinter 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named 'Tkinter' 

等错误:

>>> import tkinter 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/opt/conda/envs/pytorch-py35/lib/python3.5/tkinter/__init__.py", line 35, in <module> 
    import _tkinter # If this fails your Python may not be configured for Tk 
ImportError: libX11.so.6: cannot open shared object file: No such file or directory 

当我运行需要它的脚本:

Traceback (most recent call last): 
    File "bulk_experiment_dispatcher.py", line 18, in <module> 
    from data_file import * 
    File "/home_simulation_research/overparametrized_experiments/pytorch_experiments/data_file.py", line 16, in <module> 
    import matplotlib.pyplot as plt 
    File "/opt/conda/envs/pytorch-py35/lib/python3.5/site-packages/matplotlib/pyplot.py", line 115, in <module> 
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() 
    File "/opt/conda/envs/pytorch-py35/lib/python3.5/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup 
    globals(),locals(),[backend_name],0) 
    File "/opt/conda/envs/pytorch-py35/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module> 
    from six.moves import tkinter as Tk 
    File "/opt/conda/envs/pytorch-py35/lib/python3.5/site-packages/six.py", line 92, in __get__ 
    result = self._resolve() 
    File "/opt/conda/envs/pytorch-py35/lib/python3.5/site-packages/six.py", line 115, in _resolve 
    return _import_module(self.mod) 
    File "/opt/conda/envs/pytorch-py35/lib/python3.5/site-packages/six.py", line 82, in _import_module 
    __import__(name) 
    File "/opt/conda/envs/pytorch-py35/lib/python3.5/tkinter/__init__.py", line 35, in <module> 
    import _tkinter # If this fails your Python may not be configured for Tk 
ImportError: libX11.so.6: cannot open shared object file: No such file or directory 

我试图apt-get install python-tk(从Install tkinter for Python),但它没有工作:

[email protected]:/home_simulation_research/overparametrized_experiments/pytorch_experiments# apt-get install python-tk 
Reading package lists... Done 
Building dependency tree 
Reading state information... Done 
E: Unable to locate package python-tk 

我试图运行ENTERYPOINT为一体建议的答案,但它给我多了一些错误:

/path/fake_gui.sh: 8: /home_simulation_research/overparametrized_experiments/docker_files/runtime/fake_gui.sh: source: not found 
/path/fake_gui.sh: 12: /home_simulation_research/overparametrized_experiments/docker_files/runtime/fake_gui.sh: function: not found 
/path/fake_gui.sh: 13: kill: invalid signal number or name: SIGTERM 
/path/fake_gui.sh: 15: /home_simulation_research/overparametrized_experiments/docker_files/runtime/fake_gui.sh: Syntax error: "}" unexpected 

,但不知道该怎么办...


有用的问题:

How to install python-tk in my docker image

回答

0

与Python 3,你必须导入如下:

import tkinter # with a small caps 't' 
+0

仍然引发一个错误,但是当然要感谢那么重要:'import _tkinter#如果这个失败,你的Python可能不会被配置为Tk ImportError:libX11.so.6:无法打开共享目标文件:没有这样的文件或目录“...把原始问题的整个错误。 –

1

您需要使用已安装并运行virtual framebuffer的Docker容器。

blog post解释了将X11放入码头集装箱的“原因和方法”。

你可以看到他们是如何通过他们的entry_point.sh做它在硒多克尔容器:

#!/bin/bash 
# 
# IMPORTANT: Change this file only in directory Standalone! 

source /opt/bin/functions.sh 

export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH" 

function shutdown { 
    kill -s SIGTERM $NODE_PID 
    wait $NODE_PID 
} 

if [ ! -z "$SE_OPTS" ]; then 
    echo "appending selenium options: ${SE_OPTS}" 
fi 

SERVERNUM=$(get_server_num) 

rm -f /tmp/.X*lock 

xvfb-run -n $SERVERNUM --server-args="-screen 0 $GEOMETRY -ac +extension RANDR" \ 
    java ${JAVA_OPTS} -jar /opt/selenium/selenium-server-standalone.jar \ 
    ${SE_OPTS} & 
NODE_PID=$! 

trap shutdown SIGTERM SIGINT 
wait $NODE_PID 

来源为上面的代码是在GitHub上,SeleniumHQ/docker-selenium这个仓库。

+0

对不起,我有点困惑,这是如何在python中安装'tkinter'? –

+0

的Tkinter一般是默认安装的,但只是因为它的安装并不意味着你可以使用它。你得到的错误是因为有你的搬运工容器内没有图形用户界面。 – blakev

+0

不知道什么是错,但它扔给我一对夫妇奇怪的错误的。我想将已经包括了:'源:没有found','功能:不found','杀:无效的信号编号或名称:SIGTERM'和'语法错误: “}” unexpected'。你知道如何解决这个问题吗? –

0

好了,所以有一次我把一个虚拟屏幕上的图像在它停止崩溃:

RUN apt-get update 
RUN apt-get install -y xvfb 
#RUN Xvfb :1 -screen 0 1024x768x16 &> xvfb.log & 

,当我跑我的码头工人的形象。

相关问题