Thonny中导入numpy遇ModuleNotFoundError的路径问题求助
Fixing "ModuleNotFoundError: No module named 'numpy'" in Thonny When numpy is Already Installed
Hey there! This is a super common hiccup when your command prompt and Thonny are using different Python environments. Let's walk through how to get this sorted out quickly:
Step 1: Check which Python interpreter Thonny is using
- Open Thonny, then head to Tools > Options (or File > Settings if you're on an older version)
- Switch to the Interpreter tab—here you'll see the full path to the Python executable Thonny is currently using (e.g.,
C:\Users\JoshPC\AppData\Local\Programs\Python\Python39\python.exe)
Step 2: Verify which Python your command prompt's pip is linked to
- Go back to your command prompt and run these two commands:
where python: This lists all Python executables on your systempip --version: This will show you the exact Python version and path that yourpipis associated with (you should see something likepip 21.2.4 from c:\users\joshpc\appdata\local\programs\python\python36\lib\site-packages\pip (python 3.6))
Step 3: Align Thonny with the Python that has numpy installed
If the path from Thonny's interpreter doesn't match the one from pip --version:
- Click the Browse button in Thonny's Interpreter tab
- Navigate to the Python executable that matches your pip's path (in your case, it's
C:\Users\JoshPC\AppData\Local\Programs\Python\Python36\python.exe) - Select it, hit OK, then restart Thonny
- Try importing numpy again—this should work now!
Alternative: Install numpy directly through Thonny
If you'd rather skip the path checking, you can install numpy right in Thonny:
- Go to Tools > Manage Packages
- Type
numpyin the search bar and click Search - Click the Install button next to numpy—Thonny will install it directly to the interpreter it's currently using, so you won't have path mismatches anymore
Why this happens
Your system might have multiple Python versions installed (even if you don't remember installing them!). The
pipin your command prompt is tied to one version, but Thonny defaults to another. That's why numpy shows up as installed in the prompt but is missing in Thonny—they're looking at separate environments.
内容的提问来源于stack exchange,提问作者John Smith
相关产品推荐
相关产品推荐

