Python代码无法在Windows中执行

时间:2016-02-28 15:47:14

标签: python python-2.7

我的python代码在Ubuntu 14.04中成功运行;但是当我在Windows平台上运行时,它会让我误入歧途。 守则:

import pymc

with open("days1.txt") as f:
    dataset = map(float, f)

a = pymc.Uniform('a', lower=0, upper=1500000, value=70, doc='Weibull alpha parameter')

b = pymc.Uniform('b', lower=0, upper=1500000, value=70, doc='Weibull beta parameter')

like = pymc.Weibull('like', alpha=a, beta=b, value=dataset, observed=True)

if __name__=='__main__':

    import pylab
    M = pymc.MCMC([a,b,like])
    M.sample(10000,5000,2)
    pymc.Matplot.plot(a)
    pymc.Matplot.plot(b)
    M.summary()
    M.write_csv("parameters1.csv")  

错误:

C:\Python35-32>python.exe "E:\TCS\Desktop\EarlyWarning\JLR\Data\EJ327000AB\Scrip
ts\Screen 7\Check Python - 1\weibullEstimationOutData - 1.py"
Traceback (most recent call last):
  File "C:\Python35-32\lib\site-packages\pymc\PyMCObjects.py", line 742, in __in
it__
    self._value = np.array(value, dtype=dtype)
TypeError: float() argument must be a string or a number, not 'map'

在处理上述异常期间,发生了另一个异常:

Traceback (most recent call last):
  File "E:\TCS\Desktop\EarlyWarning\JLR\Data\EJ327000AB\Scripts\Screen 7\Check P
ython - 1\weibullEstimationOutData - 1.py", line 8, in <module>
    like = pymc.Weibull('like', alpha=a, beta=b, value=dataset, observed=True)
  AttributeError: 'TypeError' object has no attribute 'message'

请帮助。在此先感谢

1 个答案:

答案 0 :(得分:2)

您正在使用带有Ubuntu的Python 2,但带有Windows的Python 3。安装适用于Windows的Python 2,或将代码移植到Python 3

import pylab
import pymc

with open("days1.txt") as f:
    dataset = list(map(float, f))

a = pymc.Uniform('a', lower=0, upper=1500000, value=70, doc='Weibull alpha parameter')

b = pymc.Uniform('b', lower=0, upper=1500000, value=70, doc='Weibull beta parameter')

like = pymc.Weibull('like', alpha=a, beta=b, value=dataset, observed=True)

if __name__=='__main__':
    M = pymc.MCMC([a,b,like])
    M.sample(10000,5000,2)
    pymc.Matplot.plot(a)
    pymc.Matplot.plot(b)
    M.summary()
    M.write_csv("parameters1.csv")