4

I am running python3.9 on ubuntu 18.04. I already went ahead and rand the command sudo apt-get install python-scipy and got the message:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-scipy is already the newest version (0.19.1-2ubuntu1).
The following packages were automatically installed and are no longer required:
  linux-hwe-5.4-headers-5.4.0-42 linux-hwe-5.4-headers-5.4.0-53
  linux-hwe-5.4-headers-5.4.0-56 linux-hwe-5.4-headers-5.4.0-58
  linux-hwe-5.4-headers-5.4.0-59 linux-hwe-5.4-headers-5.4.0-60
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.

Yet, when I try to run my python3.9 code which uses from scipy import integrate, I get the error:

ModuleNotFoundError: No module named 'scipy'

I already read this post and tried uninstalling and installing scipy using

sudo apt-get install python3-scipy

But this did not work. Any suggestions?

Edit 1: I tried sudo pip3 install scipy which produced the message:

The directory '/home/nick/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/nick/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

Yet, when I tried to run the code again, I still get the same ImportError.

Woj
  • 449
  • 1
  • 5
  • 15

3 Answers3

5

Maybe try

python3.9 -m pip install scipy --user

which would use pip of python3.9 to install the package to a place without sudo privilege

Yang Yushi
  • 725
  • 4
  • 20
  • This is the correct answer. Both for using python -mpip, *and* user install (if not using a virtual env). – ev-br Feb 03 '21 at 18:23
  • `Requirement already satisfied: scipy in /usr/local/lib/python3.9/site-packages (1.7.3) Requirement already satisfied: numpy<1.23.0,>=1.16.5 in /usr/local/lib/python3.9/site-packages (from scipy) (1.21.4)` but still get this: `ModuleNotFoundError: No module named 'scipy'` – Dr.jacky Dec 15 '21 at 14:02
  • Hi @Dr.jacky your issue is very likely to be the mismatch between `pip` and `python`. If I were you I will check if the current `python` is indeed `python3.9` installed in `/usr/local/bin`. Sometimes there can be multiple `python3.9` in the system, which makes things very hard to work with ... – Yang Yushi Dec 21 '21 at 00:49
1

use pipwin

pip install pipwin

after download

pipwin install scipy
Rsha
  • 13
  • 3
  • 2
    While this code may provide a solution to the question, it's better to add context as to why/how it works. This can help future users learn and apply that knowledge to their own code. You are also likely to have positive-feedback/upvotes from users, when the code is explained. – Melanie Palen Feb 02 '21 at 22:28
0

Try pip3 install scipy, if that returns an ERRNO 13: access denied then try pip3 install scipy --user