Python Forum

Full Version: ModuleNotFoundError: No module named 'scipy.optimize'; 'scipy' is not a package
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Quick disclaimer: I'm still very much a beginner to python

I get the error in the title when I run

from scipy.optimize import brentq
Everything I've found regarding this issue suggests that I either do not have scipy installed (I do have it installed though) or have it installed incorrectly. Running a "pip install scipy" gives the following output:

Requirement already satisfied: scipy in c:\users\Aaron\appdata\local\programs\python\python38-32\lib\site-packages (1.5.1)
Requirement already satisfied: numpy>=1.14.5 in c:\users\Aaron\appdata\local\programs\python\python38-32\lib\site-packages (from scipy) (1.18.5)

I also found something saying that the interpreter I'm using may be the problem but it appears to be correct. The interpreter selected is:

Python 3.8 (Python Practice) C:\Users\Aaron\PycharmProjects\Python Practice\venv\Scripts\python.exe

I've successfully imported and used pylab as well as numpy so I'm not sure why scipy is being fussy. Also I'm using the PyCharm IDE if that is pertinent. Some help resolving this issue would be greatly appreciated.
You probably have a file called "scipy.py" in your PYTHONPATH (such as the current directory). It is overriding the interpreter's search for the actual scipy package.

Rename the file so it doesn't conflict.

Output:
$ python -c 'from scipy.optimize import brentq; print("ok")' ok $ touch scipy.py $ python -c 'from scipy.optimize import brentq; print("ok")' Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'scipy.optimize'; 'scipy' is not a package