2017-07-23 59 views
1

我刚买了一台新的电脑,现在一堆我的Python脚本不工作,因为他们返回以下错误:类型错误:unhashable型新计算机上,但不老

Traceback (most recent call last): 
    File "simple1.py", line 65, in <module> 
    time = np.array(simple_trajectories[0][:,0]) 
TypeError: unhashable type 

一些评论有助于查明该错误是由于simple_trajectories [0]是新计算机上的字典和旧计算机上的numpy.ndarray而产生的。

有没有办法找出为什么会发生这种情况?或者如果没有,是否有一个简单的修复方法将其改回到numpy的ndarray格式?

两台计算机都使用python 2.7.12和Ubuntu 16.04

任何建议,将不胜感激。

完整的代码粘贴在这里:

import scipy as sp 
import numpy as np 
import matplotlib.pyplot as plt 

import sys 
sys.path[:0] = ['..'] 

import gillespy 

class Simple1(gillespy.Model): 
    """ 
    This is a simple example for mass-action degradation of species S. 
    """ 

    def __init__(self, parameter_values=None): 

     # Initialize the model. 
     gillespy.Model.__init__(self, name="simple1") 

     # Parameters 
     k1 = gillespy.Parameter(name='k1', expression=0.3) 
     self.add_parameter(k1) 

     # Species 
     S = gillespy.Species(name='S', initial_value=100) 
     self.add_species(S) 

     # Reactions 
     rxn1 = gillespy.Reaction(
       name = 'S degradation', 
       reactants = {S:1}, 
       products = {}, 
       rate = k1) 
     self.add_reaction(rxn1) 
     self.timespan(np.linspace(0,20,101)) 



if __name__ == '__main__': 

    # Here, we create the model object. 
    # We could pass new parameter values to this model here if we wished. 
    simple_model = Simple1() 

    # The model object is simulated with the StochKit solver, and 25 
    # trajectories are returned. 
    num_trajectories = 250 
    simple_trajectories = simple_model.run(number_of_trajectories = num_trajectories) 




    # PLOTTING 


    # here, we will plot all trajectories with the mean overlaid 
    from matplotlib import gridspec 

    gs = gridspec.GridSpec(1,1) 


    ax0 = plt.subplot(gs[0,0]) 

    # extract time values 
    time = np.array(simple_trajectories[0][:,0]) 

    # extract just the trajectories for S into a numpy array 
    S_trajectories = np.array([simple_trajectories[i][:,1] for i in xrange(num_trajectories)]).T 

    #plot individual trajectories 
    ax0.plot(time, S_trajectories, 'gray', alpha = 0.1) 

    #plot mean 
    ax0.plot(time, S_trajectories.mean(1), 'k--', label = "Mean S") 

    #plot min-max 
    ax0.plot(time,S_trajectories.min(1), 'b--', label = "Minimum S") 
    ax0.plot(time,S_trajectories.max(1), 'r--', label = "Maximum S") 

    ax0.legend() 
    ax0.set_xlabel('Time') 
    ax0.set_ylabel('Species S Count') 

    plt.tight_layout() 
    plt.show() 

皮普冻结从旧电脑

adium-theme-ubuntu==0.3.4 
amqp==1.4.9 
anyjson==0.3.3 
Babel==1.3 
backports.shutil-get-terminal-size==1.0.0 
beautifulsoup4==4.4.1 
billiard==3.3.0.22 
boto==2.38.0 
celery==3.1.20 
chardet==2.3.0 
configparser==3.5.0 
cryptography==1.2.3 
cvxopt==1.1.4 
cycler==0.9.0 
Cython==0.23.4 
debtcollector==1.3.0 
decorator==4.0.6 
ecdsa==0.13 
entrypoints==0.2.2 
enum34==1.1.2 
funcsigs==0.4 
functools32==3.2.3.post2 
future==0.16.0 
gillespy==1.0 
gmpy==1.17 
h5py==2.6.0 
html5lib==0.999 
idna==2.0 
ipaddress==1.0.16 
ipykernel==4.5.2 
ipython==5.1.0 
ipython-genutils==0.1.0 
ipywidgets==5.2.2 
iso8601==0.1.11 
jdcal==1.0 
Jinja2==2.8 
joblib==0.9.4 
jsonschema==2.5.1 
jupyter==1.0.0 
jupyter-client==4.4.0 
jupyter-console==5.0.0 
jupyter-core==4.2.1 
keyring==7.3 
keystoneauth1==2.4.1 
kombu==3.0.33 
lxml==3.5.0 
mailer==0.7 
MarkupSafe==0.23 
matplotlib==1.5.1 
mistune==0.7.3 
monotonic==0.6 
mpmath==0.19 
msgpack-python==0.4.6 
mysql-connector-python==2.0.4 
nbconvert==4.2.0 
nbformat==4.2.0 
ndg-httpsclient==0.4.0 
netaddr==0.7.18 
netifaces==0.10.4 
nolds==0.3.2 
nose==1.3.7 
notebook==4.2.3 
numexpr==2.4.3 
numpy==1.13.1 
openpyxl==2.3.0 
oslo.i18n==3.5.0 
oslo.serialization==2.4.0 
oslo.utils==3.8.0 
pandas==0.17.1 
paramiko==1.16.0 
pathlib2==2.1.0 
patsy==0.4.1 
pbr==1.8.0 
PeakUtils==1.0.3 
pexpect==4.0.1 
pickleshare==0.7.4 
Pillow==3.1.2 
positional==1.0.1 
prettytable==0.7.2 
prompt-toolkit==1.0.9 
ptyprocess==0.5 
py==1.4.31 
pyasn1==0.1.9 
pycrypto==2.6.1 
pycurl==7.43.0 
pyeeg==0.4.0 
pyentrp==0.3.0 
pyglet==1.1.4 
Pygments==2.1.3 
pygobject==3.20.0 
PyMySQL==0.7.2 
PyOpenGL==3.0.2 
pyOpenSSL==0.15.1 
pyparsing==2.0.3 
pysb==1.2.2 
pytest==2.8.7 
python-apt==1.1.0b1 
python-dateutil==2.4.2 
python-libsbml==5.13.0 
python-memcached==1.53 
python-novaclient==3.3.1 
pytz==2014.10 
pyurdme==1.1.1 
PyYAML==3.11 
pyzmq==15.2.0 
qtconsole==4.2.1 
requests==2.9.1 
scikit-learn==0.18.1 
scipy==0.19.1 
scour==0.32 
seaborn==0.7.1 
SecretStorage==2.1.3 
selenium==3.0.2 
simplegeneric==0.8.1 
simplejson==3.8.1 
six==1.10.0 
SQLAlchemy==1.0.11 
statsmodels==0.6.1 
stevedore==1.12.0 
sympy==0.7.6.1 
tables==3.2.2 
terminado==0.6 
tornado==4.2.1 
traitlets==4.3.1 
unity-lens-photos==1.0 
urllib3==1.13.1 
VTK==5.10.1 
wcwidth==0.1.7 
widgetsnbextension==1.2.6 
wrapt==1.8.0 
xlrd==0.9.4 
xlwt==0.7.5 

皮普冻结的新计算机

adium-theme-ubuntu==0.3.4 
amqp==1.4.9 
anyjson==0.3.3 
Babel==1.3 
backports-abc==0.5 
backports.shutil-get-terminal-size==1.0.0 
beautifulsoup4==4.4.1 
billiard==3.3.0.22 
bleach==2.0.0 
boto==2.38.0 
celery==3.1.20 
certifi==2017.4.17 
chardet==2.3.0 
configparser==3.5.0 
cryptography==1.2.3 
cycler==0.10.0 
Cython==0.23.4 
debtcollector==1.3.0 
decorator==4.0.6 
ecdsa==0.13 
entrypoints==0.2.3 
enum34==1.1.2 
funcsigs==0.4 
functools32==3.2.3.post2 
gillespy==1.0 
h5py==2.7.0 
html5lib==0.999999999 
idna==2.0 
ipaddress==1.0.16 
ipykernel==4.6.1 
ipython==5.4.1 
ipython-genutils==0.2.0 
ipywidgets==6.0.0 
iso8601==0.1.11 
Jinja2==2.9.6 
jsonschema==2.6.0 
jupyter==1.0.0 
jupyter-client==5.1.0 
jupyter-console==5.1.0 
jupyter-core==4.3.0 
keyring==7.3 
keystoneauth1==2.4.1 
kombu==3.0.33 
lxml==3.5.0 
mailer==0.7 
MarkupSafe==1.0 
matplotlib==2.0.2 
mistune==0.7.4 
monotonic==0.6 
msgpack-python==0.4.6 
mysql-connector-python==2.0.4 
nbconvert==5.2.1 
nbformat==4.3.0 
ndg-httpsclient==0.4.0 
netaddr==0.7.18 
netifaces==0.10.4 
notebook==5.0.0 
numpy==1.13.1 
oslo.i18n==3.5.0 
oslo.serialization==2.4.0 
oslo.utils==3.8.0 
pandas==0.17.0 
pandocfilters==1.4.1 
paramiko==1.16.0 
pathlib2==2.3.0 
pbr==1.8.0 
PeakUtils==1.1.0 
pexpect==4.0.1 
pickleshare==0.7.4 
positional==1.0.1 
prettytable==0.7.2 
prompt-toolkit==1.0.14 
ptyprocess==0.5 
pyasn1==0.1.9 
pycrypto==2.6.1 
pycurl==7.43.0 
Pygments==2.2.0 
pygobject==3.20.0 
PyMySQL==0.7.11 
pyOpenSSL==0.15.1 
pyparsing==2.0.3 
python-apt==1.1.0b1 
python-dateutil==2.4.2 
python-libsbml==5.15.0 
python-memcached==1.53 
python-novaclient==3.3.1 
pytz==2014.10 
pyurdme==1.1.1 
PyYAML==3.11 
pyzmq==16.0.2 
qtconsole==4.3.0 
requests==2.9.1 
scandir==1.5 
scipy==0.19.1 
scour==0.32 
seaborn==0.8 
SecretStorage==2.1.3 
simplegeneric==0.8.1 
simplejson==3.8.1 
singledispatch==3.4.0.3 
six==1.10.0 
SQLAlchemy==1.0.11 
stevedore==1.12.0 
terminado==0.6 
testpath==0.3.1 
tornado==4.5.1 
traitlets==4.3.2 
unity-lens-photos==1.0 
urllib3==1.13.1 
wcwidth==0.1.7 
webencodings==0.5.1 
widgetsnbextension==2.0.0 
wrapt==1.8.0 

我会大胆的差异

+0

你能发布完整的代码吗?我们在这里没有足够的帮助你。什么是'simple_trajectories'? – Skam

+0

在处理新电脑中的列表时,我的所有脚本都会收到此错误 –

+0

比较两台电脑上“pip freeze”的输出。也许你有不同版本的numpy。 –

回答

1

参数show_labels=False添加到run()电话:

simple_trajectories = simple_model.run(number_of_trajectories=num_trajectories, show_labels=False) 

show_labels为True,run()方法的返回值是一个字典列表。当参数为False时,将返回numpy数组的列表。显然这些例子是基于show_labels=False

您可能无法依赖gillespy的版本号;这取决于你如何安装它。在文件setup.py中的setup()的调用中,版本已经在“1.0”一段时间。已进行更改而不更改版本。特别是,当添加show_labels参数时,版本未被更改。

相关问题