Cannot use scipy.stats - python-2.7

I get an errr when using scipy.stats. in a script after importing scipy.
AttributeError: 'module' object has no attribute 'stats'
Within script editor I can click on stats after typing scipy. from the pulldown menu,
within python console I can not select python.stats from the pulldown menu, it's not there.
I'm using pandas 2.7 and SciPy 0.13.0
Why is that?
Any known issues?

expanding on my comment (to have a listed answer).
Scipy, as many other large packages, doesn't import all modules automatically. If we want to use the subpackages of scipy, then we need to import them directly.
However, some scipy subpackages load other scipy subpackages, so for example importing scipy.stats also imports a large number of the other packages. But I never rely on this to have the subpackage available in the namespace.
In many packages that use scipy, the preferred pattern is to import the subpackages to have them available by their names, for example:
>>> from scipy import stats, optimize, interpolate
>>> import scipy
>>> scipy.stats
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'stats'
>>> scipy.optimize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'optimize'
>>> import scipy.stats
>>> scipy.optimize
<module 'scipy.optimize' from 'C:\Python26\lib\site-packages\scipy\optimize\__init__.pyc'>

This is expected. Most of the subpackages are not imported when you just do import scipy. There are a lot of them, with a lot of heavy extension modules that take time to load. You should always explicitly import the subpackages that you want to use.
https://github.com/scipy/scipy/issues/13618

if you import scipy alone like this:
import scipy
then you use:
scipy.stats
You will get:
AttributeError: module 'scipy' has no attribute 'stats'
You have to import like this:
import scipy.stats
or
import scipy
import stats

Related

Plot map No module named 'dbflib'

from pylab import *
import matplotlib.pyplot as plt
from matplotlib import rcParams
from matplotlib.collections import LineCollection
from mpl_toolkits.basemap import Basemap,cm
import shapefile
import dbflib
import dbflib
Traceback (most recent call last):
File "<ipython-input-398-b5a771049653>", line 1, in <module>
import dbflib
ModuleNotFoundError: No module named 'dbflib'
Tried solutions suggested by other posts like install/uninstall tookit, doesn't work. Anyone has this kind issue?

python import from relative paths

Question about setting up a relative path import. I have a bunch of files (modules) that live in
'/Users/myname/Desktop/programX_files/programX/common/
such as:
/Users/myname/Desktop/programX_files/programX/common/constants.py
/Users/myname/Desktop/programX_files/programX/common/util/misc.py
Each of those modules has a line to import other modules from within the common/ directory as needed. Examples:
"constants.py" in (/Users/myname/Desktop/programX_files/programX/common/constants.py) contains the line:
import programX.common.util.misc as util_misc
And "misc.py" in (/Users/myname/Desktop/programX_files/programX/common/util/misc.py) contains the line:
import programX.common.constants as constants
Now I want to use those modules. How do I properly let python know to set the correct path dependencies so that it will know to look into (/Users/myname/Desktop/programX_files/programX/common/) and the subdirectories inside common?
I tried appending the path, but it does not work:
>>> import sys
>>> sys.path.append('/Users/myname/Desktop/programX_files/programX/')
>>> import programX.common.constants.py as constants
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named programX.common.constants.py
>>>
>>> sys.path.append('/Users/myname/Desktop/programX_files/programX/common/')
>>> sys.path.append('/Users/myname/Desktop/programX_files/programX/common/util')
>>>
>>> import programX.common.constants.py as constants
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named programX.common.constants.py
>>>
>>> import os
>>> os.getcwd()
'/Users/myname'
>>>
>>> import Desktop.programX_files.programX.common.constants.py as constants
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Desktop.programX_files.programX.common.constants.py
>>>
I'm guessing it might be some relatively simple solution, but I can't figure it out. Thanks for the answers.
Your code should look like this:
import sys
# set path to folder
sys.path.append('/Users/myname/Desktop/programX_files/')
# now import files
import programX.common.constants.py as constants

'module' object has no attribute 'DataReader

import pandas as pd
import pandas.io.data as web # as we have to use only pandas function
#Second, retrieve the data from, say, Google itself:
stock = web.DataReader('IBM',data_source='yahoo',start='01/01/2011', end='01/01/2013')
# end of question 1
print type(stock) # Class Type is pandas.core.frame.DataFrame
IBM_dataframe = pd.DataFrame(stock)
Traceback (most recent call last):
File "", line 2, in
import pandas.io.data as web # as we have to use only pandas function
File "C:\Anaconda2\lib\site-packages\pandas\io\data.py", line 2, in
"The pandas.io.data module is moved to a separate package "
ImportError: The pandas.io.data module is moved to a separate package (pandas-datareader). After installing the pandas-datareader package (https://github.com/pydata/pandas-datareader), you can change the import from pandas.io import data, wb to from pandas_datareader import data, wb.
import pandas_datareader as web
stock = web.DataReader('IBM',data_source='yahoo',start='01/01/2011', end='01/01/2013')
Traceback (most recent call last):
File "", line 1, in
stock = web.DataReader('IBM',data_source='yahoo',start='01/01/2011', end='01/01/2013')
AttributeError: 'module' object has no attribute 'DataReader'
change the import pandas.io.data as web to import pandas_datareader as web but now not able to get data plz suggest getting error
'module' object has no attribute 'DataReader'
Use the following:
from pandas_datareader import data, wb
DAX = data.DataReader(name='^GDAXI', data_source='yahoo',start='2000-1-1')

Cron job for Django File

I want to setup a Cron job to run a django file.
What I want to know is django-cron a good option for this? i.e. or are there any other apps that can be used?
If no, how to run a django file through command line ?
admin#ADMIN-PC ~/workspace/bolt (master)
$ python ./log/cron.py
Traceback (most recent call last):
File "./log/cron.py", line 3, in <module>
from account.models import UserProfile
ImportError: No module named account.models
I have set the following variable
admin#ADMIN-PC ~/workspace/bolt (master)
$ export DJANGO_SETTINGS_MODULE=settings
I keep getting these errors as the files that are being referenced have direct imports
from foo.models import *
Any help will be highly appreciated.
Custom Command
from django.core.management.base import BaseCommand, CommandError
import pdb
import datetime
from too.models import UserProfile
from foo.api import end_all_foo_conversations
class Command(BaseCommand):
# in minutes
def handle(self,*args,**options):
print datetime
The error I am getting while trying to run the command is as follows:-
'queryset': self.rel.to._default_manager.using(db).complex_fi
imit_choices_to),
AttributeError: 'str' object has no attribute '_default_manager'
I think you should write a custom management command and run it through manage.py.

ImportError: No module named models

I am going a tad crazy here. I keep getting this error: ImportError: No module named models and I am not sure why. Here is what I have found so far...
>>> from django.shortcuts import get_object_or_404, redirect
>>> from mystore.cart import cart
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/Jeff/django/mystore/cart/cart.py", line 3, in <module>
from mystore.cart.models import CartItem
ImportError: No module named models
>>>
I am not sure what's going on with this... line 3 in cart.py is this:
from mystore.cart.models import CartItem
If I try to do: from mystore.cart.models import CartItem it works fine...
Any suggestions?
Almost certainly, you have a circular dependency: mystore.cart.cart is importing mystore.cart.models, which in turn is trying to import mystore.cart.cart.
You should determine if both of those imports are necessary, and if either of them could be moved out of the global scope into a function or method.
Why are you doing from mystore.cart import cart? That should be just from mystore import cart.
Very early in the mystore.cart.models an error is occurring that's why nothing in models.py can be imported. The error can be a circular import, a conditional statement that's triggered during runtime but not at the command prompt or is happening inside something else your are importing at the beginning of models.py
You have to put a point before.
bad
from models import *
good
from .models import *
that means that is at the same level.