简体   繁体   中英

Why do I receive a “no module named scipy” error even after I have installed the module via pip?

I am using Python 3.9 on Windows 10 which I downloaded directly from the Microsoft Store .

I tried running a script in PowerShell : Bash *.sh This script is supposed to tell my computer to execute a .py script which uses scipy.io and many other modules.

Then I received this error:

ModuleNotFoundError: No module named 'scipy'

My strategy was to make sure pip was up to date, then use it to install the desired packages, then run some commands to see if the packages were installed.

I ran this command to update pip: python3 -m pip install --upgrade pip

I ran this command to get some modules: python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose

I also tried this command just in case: pip install scipy

and got the result:

Requirement already satisfied ...

I ran the command pip list to make sure scipy was in the list (and it was there).

Then I ran the command python and my prompt changed to ">>>" and entered import scipy and did not receive any errors.

I am very confused as to how I have scipy installed yet have my script tell me it isn't there. Please help!

From what you have posted it looks like you have more than one python environment path in your system, because of which when you are installing these libraries they are installed at certain location while when you run the bash script it is using some other python location. Try using these commands in both your terminal (cmd in windows) as well as in you bash script:

import sys
print(sys.path)

This will give you the python environment path (location where your python libraries are present), then compare both the path you get from your terminal as well as bash. Add the path you got from the terminal to your global environment in order to make sure the same python version is used everywhere.

You can also refer to this: Python modules not found over terminal but on python shell, Linux

I had the same issue. You might have multiple versions of python and you only installed scipy on the one you are not using OR you are using an IDE which has the option to use packages you install that are not by default in python. Pycharm has that. When you make a new project, it has a tick option saying "Inherit global site-packages" which means it will use additional packages you have installed any.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM