brightway-lca / brightway2-data

Tools for the management of inventory databases and impact assessment methods. Part of the Brightway LCA framework.
https://docs.brightway.dev/
BSD 3-Clause "New" or "Revised" License
8 stars 21 forks source link

"ValueError: unsupported pickle protocol: 5" when importing into conda 4.10 Python 3.6 #83

Closed lelecanfora closed 2 years ago

lelecanfora commented 3 years ago

I'm on Ubuntu Linux 21.04 and I've installed this version of Anaconda: Anaconda3-2021.05-Linux-x86_64.sh

This is the procedure I've used to install Conda and Brightway2: conda create -n brightway2 python=3.6 source activate brightway2 conda install -y -q -c conda-forge -c cmutel -c haasad brightway2 jupyter

as described here: https://2.docs.brightway.dev/installation.html

Inside a notebook I try: import brightway2 as bw and this is the output:

ValueError                                Traceback (most recent call last)
<ipython-input-3-af8ad56c569b> in <module>()
      3 import numpy as np
      4 import pandas as pd
----> 5 import brightway2 as bw
      6 from brightway2 import *
      7 from bw2data.parameters import ActivityParameter, DatabaseParameter, ProjectParameter, Group

/home/lele/environments/anaconda3/envs/brightway2/lib/python3.6/site-packages/brightway2/__init__.py in <module>()
      1 # -*- coding: utf-8 -*
----> 2 from bw2data import *
      3 from bw2calc import *
      4 from bw2io import *
      5 

/home/lele/environments/anaconda3/envs/brightway2/lib/python3.6/site-packages/bw2data/__init__.py in <module>()
     33 from .project import projects
     34 from .utils import set_data_dir
---> 35 from .meta import (
     36     dynamic_calculation_setups,
     37     calculation_setups,

/home/lele/environments/anaconda3/envs/brightway2/lib/python3.6/site-packages/bw2data/meta.py in <module>()
    184 
    185 databases = Databases()
--> 186 geomapping = GeoMapping()
    187 mapping = Mapping()
    188 methods = Methods()

/home/lele/environments/anaconda3/envs/brightway2/lib/python3.6/site-packages/bw2data/meta.py in __init__(self, *args, **kwargs)
     64 
     65     def __init__(self, *args, **kwargs):
---> 66         super(GeoMapping, self).__init__(*args, **kwargs)
     67         # At a minimum, "GLO" should always be present
     68         if "GLO" not in self:

/home/lele/environments/anaconda3/envs/brightway2/lib/python3.6/site-packages/bw2data/serialization.py in __init__(self, dirpath)
    120             self.filename
    121         )
--> 122         self.load()
    123 
    124     def load(self):

/home/lele/environments/anaconda3/envs/brightway2/lib/python3.6/site-packages/bw2data/serialization.py in load(self)
    125         """Load the serialized data. Creates the file if not yet present."""
    126         try:
--> 127             self.data = self.deserialize()
    128         except IOError:
    129             # Create if not present

/home/lele/environments/anaconda3/envs/brightway2/lib/python3.6/site-packages/bw2data/serialization.py in deserialize(self)
    238 
    239     def deserialize(self):
--> 240         return self.unpack(pickle.load(open(self.filepath, "rb")))
    241 
    242 

ValueError: unsupported pickle protocol: 5
StpdFox commented 2 years ago

This is a version error with Python. Try installing python 3.8 on your environment with the command : conda install -c anaconda python=3.8

cmutel commented 2 years ago

This can still cause problems, but it's scope has been limited. The development version of bw2data explicitly uses pickle version 4, so this can only occur if you are using bw2data stable (i.e. Brightway 2 instead of 2.5), and running an environment with Python < 3.8 and another environment with Python >= 3.8. Brightway version 2 uses the highest available pickle protocol, which would then be 4/5 respectively.

So, you can easily avoid this issue by using Python >= 3.8 only, or using Brightway 2.5 (development, but stable enough for production use).