简体   繁体   English

python3.6上的tkinter在arch上具有多个版本

[英]tkinter on python3.6 with multiple versions on arch

I am trying to test out tensorflow object detection. 我正在尝试测试tensorflow对象检测。 Because tensorflow requires python3.6 and my system came with python3.7.1 installed by default I built python3.6.7 from source. 因为tensorflow需要python3.6并且我的系统默认安装了python3.7.1,所以我从源代码构建了python3.6.7。 I then created a venv with python3.6.7 and install all my dependencies but I end up getting an error when trying to import matplotlib and get the error of: 然后,我使用python3.6.7创建了一个venv并安装了我的所有依赖项,但是当尝试导入matplotlib并得到以下错误时,我最终遇到了错误:

  File "detection.py", line 9, in <module>
    from matplotlib import pyplot as plt
  File "/home/johnmadden/repos/tfobj/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2374, in <module>
    switch_backend(rcParams["backend"])
  File "/home/johnmadden/repos/tfobj/lib/python3.6/site-packages/matplotlib/pyplot.py", line 207, in switch_backend
    backend_mod = importlib.import_module(backend_name)
  File "/home/johnmadden/repos/tfobj/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/johnmadden/repos/tfobj/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py", line 1, in <module>
    from . import _backend_tk
  File "/home/johnmadden/repos/tfobj/lib/python3.6/site-packages/matplotlib/backends/_backend_tk.py", line 5, in <module>
    import tkinter as Tk
  File "/usr/local/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'

I looked online and found out that I needed to install tk with 我在网上看了看,发现我需要用

pacman -S tk

And I still get the same error, but when I go to python3.7.1 it import sucessfully. 而且我仍然遇到相同的错误,但是当我转到python3.7.1时,它成功导入。 I think that it is trying to install it for python3.7.1 and not python3.6.7. 我认为它正在尝试为python3.7.1而不是python3.6.7安装它。 I know that on ubuntu people can do 我知道在ubuntu上人们可以做到

sudo apt-get install python3-tk

How would this be accomplished on arch? 如何在拱门上完成?

Found my problem, I created venv before installing tk so it was still missing it. 发现我的问题后,我在安装tk之前创建了venv,因此它仍然丢失。 I just recreated the virtual environment. 我只是重新创建了虚拟环境。

The actual answer is that tensorflow does not require python 3.6 -- Arch Linux provides a tensorflow package that has been patched to build against python 3.7, and you should use that instead. 实际的答案是tensorflow不需要python 3.6-Arch Linux提供了一个tensorflow软件包,该软件包已打补丁以针对python 3.7构建,您应该改用它。 If you build your own python and tensorflow, then you run the risk of messing up part or all of the installation (in this case, failing to get tkinter correctly set up). 如果您构建自己的python和tensorflow,则冒着将部分或全部安装弄乱的风险(在这种情况下,将无法正确设置tkinter)。

The first thing you should always do is check if the software you want is already available in the distribution repositories -- if it is, then the package is definitely intended to work with the ecosystem provided by those distribution repositories. 您应该始终做的第一件事是检查所需的软件是否已在发行版本存储库中提供-如果已可用,则该软件包肯定旨在与那些发行版本存储库提供的生态系统一起使用。

In this case, you can see that the tensorflow package has a number of patches to fix build failures on python 3.7: https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/tensorflow&id=ef98a003237250ba0853990da1742ee27c0e554d#n37 在这种情况下,您可以看到tensorflow软件包具有许多补丁来修复python 3.7上的构建失败: https ://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages / tensorflow&ID =#ef98a003237250ba0853990da1742ee27c0e554d N37

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM