简体   繁体   中英

tkinter on python3.6 with multiple versions on arch

I am trying to test out tensorflow object detection. Because tensorflow requires python3.6 and my system came with python3.7.1 installed by default I built python3.6.7 from source. 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:

  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. I think that it is trying to install it for python3.7.1 and not python3.6.7. I know that on ubuntu people can do

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. 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. 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).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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