【发布时间】:2019-12-24 14:43:15
【问题描述】:
我对 Python 很陌生。安装包 cosmoTransitions 后,我必须运行代码,并且有一些示例程序,我已经尝试过一个并收到下面提到的错误,但不明白错误来自哪里
def approxZeroTMin(self):
# There are generically two minima at zero temperature in this model,
# and we want to include both of them.
v = v2**.5
return [np.array([v,v,v]), np.array([v,v,v])]
def makePlots(m=None):
import matplotlib.pyplot as plt
if m is None:
m = model1()
m.findAllTransitions()
# --
plt.figure()
m.plotPhasesPhi()
plt.axis([0,300,-50,550])
plt.title("Minima as a function of temperature")
plt.show()
# --
plt.figure(figsize=(8,3))
ax = plt.subplot(131)
T = 0
m.plot2d((-450,450,-450,450), T=T, cfrac=.4,clevs=65,n=100,lw=.5)
ax.set_aspect('equal')
ax.set_title("$T = %0.2f$" % T)
ax.set_xlabel(R"$\phi_1$")
ax.set_ylabel(R"$\phi_2$")
ax = plt.subplot(132)
T = m.TnTrans[1]['Tnuc']
instanton = m.TnTrans[1]['instanton']
phi = instanton.Phi
m.plot2d((-450,450,-450,450), T=T, cfrac=.4,clevs=65,n=100,lw=.5)
ax.plot(phi[:,0], phi[:,1], 'k')
ax.set_aspect('equal')
ax.set_title("$T = %0.2f$" % T)
ax.set_yticklabels([])
ax.set_xlabel(R"$\phi_1$")
ax = plt.subplot(133)
T = m.TnTrans[0]['Tnuc']
m.plot2d((-450,450,-450,450), T=T, cfrac=.4,clevs=65,n=100,lw=.5)
ax.set_aspect('equal')
ax.set_title("$T = %0.2f$" % T)
ax.set_yticklabels([])
ax.set_xlabel(R"$\phi_1$")
# --
plt.figure()
plt.plot(instanton.profile1D.R, instanton.profile1D.Phi)
plt.xlabel("radius")
plt.ylabel(R"$\phi-\phi_{min}$ (along the path)")
plt.title("Tunneling profile")
但是在运行它之后它显示了太多错误,我也无法区分它们来自哪里。 这是错误消息:
Traceback (most recent call last):
File "C:/Users/SATYABRATA/AppData/Local/Programs/Python/Python38-32 /sdd.py", line 2, in <module>
from cosmoTransitions import generic_potential
File "C:\Users\SATYABRATA\AppData\Local\Programs\Python\Python38-32 \lib\site-packages\cosmoTransitions\generic_potential.py", line 20, in <module>
from .finiteT import Jb_spline as Jb
File "C:\Users\SATYABRATA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cosmoTransitions\finiteT.py", line 25, in <module>
from scipy.misc import factorial as fac
ImportError: cannot import name 'factorial' from 'scipy.misc' (C:\Users \SATYABRATA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\scipy\misc\__init__.py)
【问题讨论】:
-
Please don't post screenshots of text。它们无法被搜索或复制,并且可用性差。相反,将代码作为文本直接粘贴到您的问题中。如果选择它并单击
{}按钮或Ctrl+K,则代码块将缩进四个空格,这将导致其呈现为代码。 -
你安装了 scipy 吗?
-
是的 scipy、numpy、matplotlib、cosmoTransitions 全部安装
-
docs.scipy.org/doc/scipy-1.1.0/reference/generated/… 说 scipy.misc.factorial 已被贬低。如果您已经拥有最新版本的 cosmoTransitions(可能尝试查找开发版本),您可以尝试将 scipy 替换为旧版本。或者尝试更改源以用 scipy.special.factorial 替换对 scipy.misc.factorial 的调用
-
在 shell 中尝试
from scipy.special import factorial,如果可行,更改finiteT.py中的那一行并向维护者提供反馈。