PyCharm无法导入numpy求助:已装Anaconda,Python新手遇ModuleNotFoundError
Fixing ModuleNotFoundError for numpy in PyCharm with Anaconda
Hey there! Let's get that numpy import working—this issue almost always happens because PyCharm isn't using your Anaconda environment (where numpy is installed). Here's how to fix it step by step:
1. Check your PyCharm Python Interpreter settings
- Open PyCharm, then go to File > Settings (Windows/Linux) or PyCharm > Settings (Mac).
- In the left sidebar, navigate to Project: [Your Project Name] > Python Interpreter.
- Look at the interpreter path shown at the top of the window. It should point to the Python executable inside your Anaconda installation folder (e.g.,
C:\Users\YourName\anaconda3\python.exeon Windows,~/anaconda3/bin/pythonon Mac/Linux).
2. Switch to your Anaconda environment if needed
If the current interpreter isn't the Anaconda one:
- Click the gear icon next to the interpreter dropdown, then select Add.
- In the new window, choose Conda Environment > Existing environment.
- Click the
...button to browse and select the Python executable from your Anaconda directory. - Optional: Check "Make available to all projects" so you don't have to repeat this for future projects.
- Click OK to save the setting.
3. Verify and test
- Go back to your code and run the
import numpyline again—it should work now. - If you still run into issues, open PyCharm's built-in Terminal and run
conda listto confirm numpy is installed. If it's missing, just runconda install numpydirectly in the Terminal (it will use the Anaconda environment you just set up).
Quick tip: If you just installed Anaconda, restart PyCharm first—sometimes the IDE needs a refresh to pick up new environment variables.
内容的提问来源于stack exchange,提问作者Nicole I.
相关产品推荐
相关产品推荐

