新Mac配置Python/PyCharm时虚拟环境无法找到scipy求助
Hey, let’s troubleshoot this annoying scipy issue together—I’ve run into similar IDE vs terminal package mismatches before, so we’ll get it sorted. Here are the most likely fixes to try in order:
1. Double-check your PyCharm interpreter configuration
First, make sure PyCharm is definitely using the exact virtual environment you set up in the terminal:
- Open PyCharm’s Preferences (or Settings on Windows/Linux)
- Navigate to Project: TernaryTest > Python Interpreter
- Verify the selected interpreter path matches your venv:
~/PycharmProjects/TernaryTest/venv/bin/python3.7 - Look for
scipyin the list of installed packages. If it’s missing here but shows up in your terminal, PyCharm hasn’t synced the package list yet.
2. Refresh PyCharm’s package cache
PyCharm doesn’t always auto-detect packages installed via the system terminal. To force a refresh:
- In the Python Interpreter settings page, click the circular refresh icon in the top-right corner
- Wait for PyCharm to re-scan your venv’s
site-packagesdirectory. Once done, check ifscipyappears in the package list.
3. Install scipy directly through PyCharm
If refreshing doesn’t work, bypass the terminal entirely and install scipy within PyCharm:
- In the Python Interpreter settings, click the
+button to add a new package - Search for
scipy, select version 1.4.1 (to match what you installed in the terminal), and click Install Package - This ensures PyCharm installs the package directly into the venv it’s using, eliminating any path mismatches.
4. Verify your run configuration
Sometimes the run configuration uses a different interpreter than your project default:
- Click the dropdown menu next to the run button (top-right corner of PyCharm)
- Select Edit Configurations
- In the configuration window, check that the Python interpreter is set to your
TernaryTestvenv - Save the configuration and try running your code again.
5. Do a full PyCharm restart
Occasionally, IDE caches get stuck. Quit PyCharm completely (don’t just minimize it), wait 10 seconds, then reopen it. This forces PyCharm to reload all environment and package data from scratch.
6. Check PyCharm’s built-in terminal
Open PyCharm’s internal terminal (bottom toolbar, click Terminal) and run these commands to confirm the environment is correctly linked:
- Activate the venv if it’s not already active:
source ~/PycharmProjects/TernaryTest/venv/bin/activate - Run
which python—it should output the venv’s Python path - Run
pip list—you should seescipylisted here
If these don’t match your system terminal’s output, PyCharm isn’t properly accessing your venv, and you may need to re-add the interpreter in settings.
One of these steps should resolve the ModuleNotFoundError—usually it’s either a cache refresh or a misconfigured interpreter/run setup.
内容的提问来源于stack exchange,提问作者N. Mao

