为什么 conda install tk 在我的 docker 容器中不起作用,即使它说已安装?

2023-12-23

我遇到了问题tk在我的 python 3 docker 容器中。

I tried:

conda install tk

但它说它确实安装了

root@36602e2cd649:/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

I tried apt-get install python-tk (from 安装 Python 版 tkinter https://stackoverflow.com/questions/4783810/install-tkinter-for-python)但它不起作用:

root@36602e2cd649:/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

但不知道该怎么办...


有用的问题:

如何在我的 docker 镜像中安装 python-tk https://stackoverflow.com/questions/45289891/how-to-install-python-tk-in-my-docker-image


您需要使用具有以下功能的 Docker 容器:虚拟帧缓冲区 https://en.wikipedia.org/wiki/Xvfb安装并运行。

This 博客文章 https://linuxmeerkat.wordpress.com/2014/10/17/running-a-gui-application-in-a-docker-container/解释了将 X11 放入 docker 容器的“原因和方式”。

您可以通过他们的 Selenium Docker 容器了解他们是如何做到这一点的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 https://github.com/SeleniumHQ/docker-selenium/tree/master/StandaloneChrome.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 conda install tk 在我的 docker 容器中不起作用,即使它说已安装? 的相关文章

随机推荐