Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named scipy.stats - Why despite scipy being installed

Tags:

python

scipy

How to use python and scipy to get a poissio random variable? Wow..I installed scipy and per the docs I get No module named scipy.stats? I am on ubuntu 12.04. So......go figure

http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.poisson.html

ubuntu@ubuntu:~/Downloads$ sudo apt-get install python-scipy
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-scipy is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 482 not upgraded.
ubuntu@ubuntu:~/Downloads$ python
Python 2.7.3 (default, Apr 10 2013, 06:20:15) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from scipy.stats import poisson
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named scipy.stats
like image 378
Tampa Avatar asked Oct 09 '13 00:10

Tampa


4 Answers

I think scipy is the way to go. Probably you have a simple namespace visibility problem. since stats is itself a module you first need to import it, then you can use functions from scipy.stats

import scipy
import scipy.stats
#now you can use
scipy.stats.poisson
#if you want it more accessible you could do what you did above
from scipy.stats import poisson
#then call poisson directly
poisson
like image 147
Paul Avatar answered Oct 27 '22 17:10

Paul


pip install --upgrade --force-reinstall scipy

like image 28
Apoorva Malemath Avatar answered Oct 27 '22 17:10

Apoorva Malemath


I accidentally caused this issue by naming one of my scipy test programs "scipy.py". Of course, this makes any "import scipy" in this directory import my test program, not the system library, in turn resulting in lots of errors like:

ImportError: No module named stats

It's embarrassing how long it took me to figure this out!

like image 37
Orion Lawlor Avatar answered Oct 27 '22 17:10

Orion Lawlor


I had a similar issue with Python 3.4 on my Windows 7 machine. I had to update my scipy package 'pip install --upgrade scipy'

like image 1
djm457 Avatar answered Oct 27 '22 17:10

djm457