问题
I've been using Python only a couple years, primarily through Jupyter notebooks and Spyder, which came with Anaconda. I'm starting to use IDLE some and have problems with loading packages. I'm wondering if the issue stems from the fact I have different Python executables, one used by Jupyter/Spyder and the other by IDLE.
In IDLE, I typed
import sys; print(sys.executable)
which resulted in
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
In both Spyder and in a Jupyter notebook, I also typed
import sys; print(sys.executable)
which resulted in
/Users/fishbacp/anaconda3/bin/python
Spyder indicates it's using Python 3.7 as well.
While I've installed numpy and a plethora of packages for use in Spyder/Jupyter, no such packages can currently be imported within the IDLE shell. A simple "ModuleNotFoundError" results. Because I have so many packages already installed, I'd rather not re-install them for use in IDLE.
Is there a simple way for me to configure IDLE so that it uses the 3.7 located in /Users/fishbacp/anaconda3/bin/python?
If it's relevant, my machine is a Mac running Catalina 10.15.4.
回答1:
IDLE is run by whatever python you explicitly or implicitly ask to run IDLE. The icon installed by the python.org installer at some point executes something like
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -m idlelib
In Terminal, you could execute
/Users/fishbacp/anaconda3/bin/python -m idlelib
However, there might be issues with the version of tcl/tk associated with that python, if different, especially on Catalina. See IDLE's Help => About IDLE for the tk x.y.z version.
You may be better off with 3.8.2 (or soon, 3.8.3).
来源:https://stackoverflow.com/questions/61395180/how-to-set-python-executable-path-in-idle