I am running a program in the SciTE text editor and it gets stuck at the import scipy as sp statement.
import pylab as pl
import numpy as np
import scipy as sp
import scipy.integrate as spi
import scipy.optimize as spo
import numpy.random as nr
import matplotlib.pyplot as plt
print "check"
#parameters to be used
rs=0.14
ra=0.0027
js=-0.033
ja=0.81
Mz=91.0
Tz=2.5
root_s=sp.linspace(20.,140.,200) #plotting sigma_A and sigma_S functions against centre of mass energies from 20GeV to 140 GeV
s=(root_s)**2
.....
.....
and I get this error message:
>pythonw -u "collisions.py"
3.14159265359
1.0
Traceback (most recent call last):
File "collisions.py", line 4, in <module>
import scipy as sp
File "C:\Python27\lib\site-packages\scipy\__init__.py", line 85, in <module>
from numpy import oldnumeric
File "C:\Python27\lib\site-packages\numpy\oldnumeric\__init__.py", line 14, in <module>
from compat import *
File "C:\Python27\lib\site-packages\numpy\oldnumeric\compat.py", line 106, in <module>
class Unpickler(pickle.Unpickler):
AttributeError: 'module' object has no attribute 'Unpickler'
>Exit code: 1
The odd thing is that my code works perfectly fine in the interactive qtconsole. I am new to programming, and I have not encountered such a problem elsewhere in the internet. And why is it that the values pi and 1.0 are returned even though there is no where in my code that is supposed to do that?
Related
I have to create popup dialog box which contains text field using tkinter module in Python 2(not Python 3). My other program has many Python2 modules(I have written whole code in Python 2) and so I can't go for Python 3. Here is my code which works fine in Python 3 but not in Python 2.
from tkinter import simpledialog
from tkinter import *
def s():
print(simpledialog.askstring("hai","inp"))
root = Tk()
b = Button(root, text="popup",command=s)
b.pack()
root.geometry("400x400")
root.mainloop()
This is the error :
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1550, in __call__
return self.func(*args)
File "popup.py", line 4, in s
print(simpledialog.askstring("hai","inp"))
AttributeError: 'module' object has no attribute 'askstring'
Please mention any alternatives to achieve this function in Python 2.
Thank you
Just change
from tkinter import simpledialog
from tkinter import *
to
import tkSimpleDialog as simpledialog
from Tkinter import *
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?
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')
Here is my my code
import theano
import numpy
import os
from keras.models import Sequential
model2 = Sequential()
model2.load_weights("/home/console/Desktop/Apu_code/_epoch_0_e199-0.04.hdf5")
'''model = loaded_models('.)'''
print('loaded')
and getting error :
Using Theano backend.
Traceback (most recent call last):
File "try.py", line 7, in <module>
model2.load_weights("/home/console/Desktop/Apu_code/_epoch_0_e199-0.04.hdf5")
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2369, in load_weights
str(len(flattened_layers)) + ' layers.')
Exception: You are trying to load a weight file containing 12 layers into a model with 0 layers.
I just do
model0 = keras.models.load_model(hdf5Fname)
to load the file into the variable model0 in order to do sth like
prediction0 = model0.predict( image)[0][0]
and so on...
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