TypeError:新计算机上的不可用类型,但不是旧的

时间:2017-07-23 00:31:58

标签: python numpy

我刚买了一台新电脑,现在我的一些python脚本不能正常工作,因为它们会返回以下错误:

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()

Pip Freeze from old computer

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

从新电脑中冻结P

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

我会大胆分歧

1 个答案:

答案 0 :(得分: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()的{​​{1}}调用中,版本暂时处于“1.0”状态。在不更改版本的情况下进行了更改。特别是,当添加setup.py参数时,版本未更改。