Cant import scipy.stats

Asked by Andres Escobar

Hello, I am currently trying to run a Yade script which requires scipy.stats, however when y try to import it I get the following message:

import scipy.stats

ModuleNotFoundError: No module named 'scipy'

===
However this module is installed, as I can successfully import it using python3. I have already run the prerequisites codes which appears on the 'installation' page with no results.

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Andres Escobar
Solved:
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hello,

we need more information [1].
- what is your OS?
- what is your Yade version?
- how did you install Yade?
- Yade uses python 2 or 3 (what does yade print at startup)?
- ...

My personal tip is Python2/3 clash.

cheers
Jan

[1] https://www.yade-dem.org/wiki/Howtoask

Revision history for this message
Andres Escobar (afer95) said :
#2

Thanks for your answer,
I am using Ubuntu 20.04.1. And I am using yade 2020.01a as stated below. I did install it through the terminal as indicated on the instalation guide with: "sudo apt-get install yade"

(base) utilisateur_01@GRP3854-L01:~$ yade
Welcome to Yade 2020.01a
Using python version: 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0]
TCP python prompt on localhost:9000, auth cookie `dskeyu'
XMLRPC info provider on http://localhost:21000
[[ ^L clears screen, ^U kills line. F12 controller, F11 3D view (press "h" in 3D view for help), F10 both, F9 generator, F8 plot. ]]

Revision history for this message
Jan Stránský (honzik) said :
#3

Thanks, so Python2 is out :-)

> However this module is installed, as I can successfully import it using python3

- how did you install scipy (if you remember)?
- how do you use python3?

cheers
Jan

Revision history for this message
Janek Kozicki (cosurgi) said :
#4

Just to be sure that scipy for python3 is installed: start in terminal: python3
then try to import scipy

Revision history for this message
Andres Escobar (afer95) said :
#5

Hello,

I did install it last through anaconda if I remember well. I use python with Spyder, and sometimes with the terminal.

As suggested, spicy is successfully imported using python 3:

(base) utilisateur_01@GRP3854-L01:~$ python3
Python 3.8.3 (default, Jul 2 2020, 16:21:59)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>>

However, when importing it using yade, it is not recognized:

(base) utilisateur_01@GRP3854-L01:~$ yade
Welcome to Yade 2020.01a
Using python version: 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0]
TCP python prompt on localhost:9000, auth cookie `usdske'
XMLRPC info provider on http://localhost:21000
[[ ^L clears screen, ^U kills line. F12 controller, F11 3D view (press "h" in 3D view for help), F10 both, F9 generator, F8 plot. ]]

In [1]: import spicy
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
/usr/bin/yade in <module>
----> 1 import spicy

ModuleNotFoundError: No module named 'spicy'

In [2]:

Revision history for this message
Jan Stránský (honzik) said :
#6

your python:
> Python 3.8.3 (default, Jul 2 2020, 16:21:59)
your yade:
> Using python version: 3.8.5 (default, Jul 28 2020, 12:59:40)

you have different python versions, obviously without shared scipy

> I did install it last through anaconda if I remember well. I use python with Spyder, and sometimes with the terminal.

probably because of this

The solution is to install scipy for the Python, which Yade is using.
The easiest way is
sudo apt install python-scipy
which install scipy "globally" (with all pros and cons)

cheers
Jan

Revision history for this message
Janek Kozicki (cosurgi) said :
#7

> ModuleNotFoundError: No module named 'spicy'

Also beware of typos. spicy is not scipy :)

Revision history for this message
Andres Escobar (afer95) said :
#8

Thank you for your answer, It was a type, yet I had the same outcome:

(base) utilisateur_01@GRP3854-L01:~$ yade
Welcome to Yade 2020.01a
Using python version: 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0]
TCP python prompt on localhost:9000, auth cookie `ckssay'
XMLRPC info provider on http://localhost:21000
[[ ^L clears screen, ^U kills line. F12 controller, F11 3D view (press "h" in 3D view for help), F10 both, F9 generator, F8 plot. ]]

In [1]: import scipy
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
/usr/bin/yade in <module>
----> 1 import scipy

ModuleNotFoundError: No module named 'scipy'

While trying to apply your solution, I cannot install scipy "globally" as I get a message telling me that there is another source for this:

(base) utilisateur_01@GRP3854-L01:~$ sudo apt install python-scipy
[sudo] Mot de passe de utilisateur_01 :
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances
Lecture des informations d'état... Fait
Aucune version du paquet python-scipy n'est disponible, mais il existe dans la base
de données. Cela signifie en général que le paquet est manquant, qu'il est devenu obsolète
ou qu'il n'est disponible que sur une autre source

E: Le paquet « python-scipy » n'a pas de version susceptible d'être installée

Sorry that it is in French. Hence I as I can not install scipy globally, I think I should try to uninstall Anaconda and try again.

Thank you very much for your support :)

Revision history for this message
Jan Stránský (honzik) said :
#9

> I cannot install scipy "globally" as I get a message telling me that there is another source for this:
> I think I should try to uninstall Anaconda and try again.

might help.
Working with multiple python versions might be tricky and confusing, I personally try to avoid this, although I believe there are good tolls for this and they (should) have the ability to handle this kind of problem (but I have no experience).

cheers
Jan

Revision history for this message
Manfred Hampl (m-hampl) said :
#10

You probably need to install python3-scipy (and not python-scipy)

For debugging purposes you could check the path where modules are searched in both your python and yade installations
print(sys.path)

Revision history for this message
Andres Escobar (afer95) said :
#11

Thank you for your answers, I tried the solution proposed by Jan Stránský (honzik) and it worked, I managed to get both python and yade to use the same python version. However I could not install scipy. After trying Manfred Hampl (m-hampl) approach, I managed to successfully doing it.
Thank you very much for you attention and help on this issue!