jakeret / hope

HOPE: A Python Just-In-Time compiler for astrophysical computations
GNU General Public License v3.0
382 stars 27 forks source link

error when trying to compile function -- unsupported pickle protocol: 3 #26

Closed astronomeralex closed 10 years ago

astronomeralex commented 10 years ago

I'm using hope 0.3.1 (upgraded today), anaconda python2.7 on Mac 10.9.5 with clang 3.4.

When I try to follow the very simple example of the sum function using hope in ipython 2.2.0, I get this error.

In [1]: from hope import jit

In [2]: @jit
   ...: def jitsum(x,y):
   ...:     return x + y
   ...: 
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-cc998918d205> in <module>()
----> 1 @jit
      2 def jitsum(x,y):
      3     return x + y
      4 

/astro/grads/arh5361/code/anaconda/envs/py27/lib/python2.7/site-packages/hope/jit.pyc in jit(fkt)
     87 
     88     try:
---> 89         state = serialization.unserialize(filename)
     90         if not state is None:
     91             _check_state(fkt, state)

/astro/grads/arh5361/code/anaconda/envs/py27/lib/python2.7/site-packages/hope/serialization.pyc in unserialize(name)
     40 
     41     with open(os.path.join(config.prefix, "{0}.pck".format(name)), "rb") as fp:
---> 42         return pickle.load(fp)

/astro/grads/arh5361/code/anaconda/envs/py27/lib/python2.7/pickle.pyc in load(file)
   1376 
   1377 def load(file):
-> 1378     return Unpickler(file).load()
   1379 
   1380 def loads(str):

/astro/grads/arh5361/code/anaconda/envs/py27/lib/python2.7/pickle.pyc in load(self)
    856             while 1:
    857                 key = read(1)
--> 858                 dispatch[key](self)
    859         except _Stop, stopinst:
    860             return stopinst.value

/astro/grads/arh5361/code/anaconda/envs/py27/lib/python2.7/pickle.pyc in load_proto(self)
    884         proto = ord(self.read(1))
    885         if not 0 <= proto <= 2:
--> 886             raise ValueError, "unsupported pickle protocol: %d" % proto
    887     dispatch[PROTO] = load_proto
    888 

ValueError: unsupported pickle protocol: 3
cosmo-ethz commented 10 years ago

@astronomeralex this happens if you have been using HOPE with Python 3 and then with Python 2. Could you try to remove the HOPE cache by deleting the .hope folder and then to rerun your test?

astronomeralex commented 10 years ago

@cosmo-ethz thanks! it works now. is it worth me trying to add to the code so this doesn't happen for other folks?

cosmo-ethz commented 10 years ago

@astronomeralex I think it would be fairly easy to surround it with a try-except block. However, it’s a bit questionable how likely it is that somebody is switching back and forth between two Python version (except if testing something).