The thing is this: a friend in learning to use matplotlib mapping, encountered some questions asked me, I have not used, I would like to put a try first. Then, I created a virtual environment at my fingertips. As a result, the first line involving Matplotlib is an error:
Traceback (most recent call last): File "d:/workspace/pytest/get_data.py", line A, in <module> Plt.scatter (x[:5 0, 0], x[:50, 1], color= "Red", marker= "O", label= "Setosa") File "D:\workspace\PyTest\py3env\lib\site-packages\ matplotlib\pyplot.py ", line 3420, in scatter ax = GCA () File" D:\workspace\PyTest\py3env\lib\site-packages\matplotlib\ pyplot.py ", line 950, in GCA return GCF (). GCA (**kwargs) File" D:\workspace\PyTest\py3env\lib\site-packages\matplotlib\ pyplot.py ", line 586, in GCF return figure () File" D:\workspace\PyTest\py3env\lib\site-packages\matplotlib\pyplot.py ", Line 535, in Figure **kwargs) File "D:\WORKSPACE\PYTEST\PY3ENV\LIB\SITE-PACKAGES\MATPLOTLIB\BACKENDS\BACKEND_TKAGG.P Y ", line Bayi, in New_figure_manager return new_figure_manager_given_figure (num, figure) File" D:\workspace\PyTest\py3en v\lib\site-packages\matplotlib\backends\backend_tkagg.py ", line, new_figure_manager_given_figure window = Tk.Tk () File "C:\Python35\Lib\tkinter\__init__.py ", line 1868, in __init__ self.tk = _tkinter.create (screenname, BaseName, className, Interactive, wantobjects, u SETK, sync, use)_tkinter. Tclerror:can ' t find a usable init.tcl in the following directories:c:/python35/lib/tcl8.6 d:/workspace/pytest/py3env /lib/tcl8.6 d:/workspace/pytest/lib/tcl8.6 d:/workspace/pytest/py3env/library D:/workspace/PyTest/library D:/ Workspace/pytest/tcl8.6.4/library d:/workspace/tcl8.6.4/librarythis probably means that Tcl wasn ' t installed properly.
After analysis, I think this is because I did not find Tkinter, and matplotlib need to use this. But this thing is the default when it comes to Python, and I'm sure it will. I turned over my computer, TCL is really installed:
But the path is wrong. Through the group of students guidance, I also deliberately tested in the main environment of TK and TCL Environment:
Import= tkinter. Tk ()print(root.tk.exprstring ('$tcl _library'))print( Root.tk.exprstring ('$tk _library'))
The results are also normal in the main environment:
C:\Python35\tcl\tcl8.6C:/python35/tcl/tk8.6
But it's not normal in a virtual environment.
Traceback (most recent): File "d:/workspace/pytest/testtk.py", line 2, in <module> root = Tkinter . Tk () File "C:\Python35\Lib\tkinter\__init__.py", line 1868, in __init__ self.tk = _tkinter.create (screenname, BaseName, ClassName, Interactive, wantobjects, USETK, sync, use) _tkinter. Tclerror:can ' t find a usable INIT.TCL in the following directories: c:/python35/lib/tcl8.6 d:/workspace/pytest/ py3env/lib/tcl8.6 d:/workspace/pytest/lib/tcl8.6 d:/workspace/pytest/py3env/library D:/workspace/PyTest/library D :/workspace/pytest/tcl8.6.4/library d:/workspace/tcl8.6.4/librarythis probably means that Tcl wasn ' t installed properly.
That would be embarrassing.
However, I also notice a detail: Tcl when looking for the environment, will find the main python environment of the machine, such as the previous error, Tcl looked for such two environments:
c:/python35/lib/tcl8.6D:/workspace/pytest/py3env/lib/tcl8.6
where C drive is my main environment, D:/WORKSPACE/PYTEST/PY3ENV is a virtual environment.
Then I started flipping through the code to see what the TCL query path was. Not found. On-Line Introduction to add environment variables, tcl_library and tk_library, I tried also not (perhaps these two variables are limited to Linux system), in the path add also does not work.
Desperate circumstances I began to move the brain, the Tcl8.6 entire folder from C:\Python35\tcl\ copied to the C:\Python35\Lib, and then, incredibly ...
Traceback (most recent): File "d:/workspace/pytest/ml/mcpperceptron/get_data.py", line A, in <module> Plt.scatter (x[:50, 0], x[:50, 1], color= "Red", marker= "O", label= "Setosa") File "D:\workspace\PyTest\py3env\lib\ site-packages\matplotlib\pyplot.py ", line 3420, in scatter ax = GCA () File" D:\workspace\PyTest\py3env\lib\site-packag es\matplotlib\pyplot.py ", line 950, in GCA return GCF (). GCA (**kwargs) File" D:\workspace\PyTest\py3env\lib\site-packag es\matplotlib\pyplot.py ", line 586, in GCF return figure () File" D:\workspace\PyTest\py3env\lib\site-packages\matplotl ib\pyplot.py ", line 535, and figure **kwargs) File" D:\workspace\PyTest\py3env\lib\site-packages\matplotlib\backends\b ackend_tkagg.py ", line Bayi, in New_figure_manager return new_figure_manager_given_figure (num, figure) File" D:\workspac e\pytest\py3env\lib\site-packages\matplotlib\backends\backend_tkagg.py ", Line New_figure_manager_given_ Figure window = tk.tk () File "C:\Python35\lib\tkinter\__init__.py ", line 1868, in __init__ self.tk = _tkinter.create (screenname, BaseName, ClassName, Interactiv E, wantobjects, USETK, sync, use)_tkinter. Tclerror:can ' t find a usableTK.TCLIn the following directories: c:/python35/lib/tcl8.6/tk8.6 c:/python35/lib/tk8.6 d:/workspace/pytest/py 3env/lib/tk8.6 d:/workspace/pytest/lib/tk8.6 d:/workspace/pytest/py3env/librarythis probably means that tk Wasn ' t installed properly.
The error of the report from "Can not find Tcl" became "Can not find TK"!
Did you say it was successful? So, I followed suit, the tk8.6 folder from the C:\Python35\tcl\ copied to the C:\Python35\Lib\tcl8.6.
And then it really worked!
What a problem! ╭ (╯^╰) ╮
Well, just to be warned, in a virtual environment in Windows, if you use TK, note the path of Tcl and Tk. The entire directory can be copied to the Tcl and TK search paths. As for what it is called, I do not know.
Using TK in a virtual environment under Windows, be careful