polca / premise

Coupling Integrated Assessment Models output with Life Cycle Assessment.
BSD 3-Clause "New" or "Revised" License
101 stars 45 forks source link

ImportError DLL load failed while importing _openssl. when extracting iam data #113

Closed GemmaCC18 closed 5 months ago

GemmaCC18 commented 11 months ago

Hi there,

I just tried to use premise v.(1, 6, 7) and wanted to create some scenarios using REMIND's SSP2 Base pathway, from ecoinvent 3.9.1 for the years 2020,2025,2030 and 2050, but got the following error message. Specifically, this error occurred in the step of EXTRACTING IAM DATA.

I installed the openssl package again, but still couldn't fix the error. Could anyone help me with this issue? Thank you in advance

code:

ndb = NewDatabase( scenarios=[ {"model":"remind", "pathway":"SSP2-Base", "year":2030}, {"model":"remind", "pathway":"SSP2-Base", "year":2035}, ], source_db="cutoff391", source_version="3.9.1", key='xxx', )

Here is the detailed error info: `File ~\Anaconda3\envs\plca_env\lib\site-packages\premise\ecoinvent_modification.py:609, in NewDatabase.init(self, scenarios, source_version, source_type, key, source_db, source_file_path, additional_inventories, system_model, system_args, use_cached_inventories, use_cached_database, external_scenarios, quiet, keep_uncertainty_data, gains_scenario, use_absolute_efficiency) 607 # use multiprocessing to speed up the process 608 with Pool(processes=multiprocessing.cpu_count()) as pool: --> 609 pool.map(_fetch_iam_data, self.scenarios) 611 print("Done!")

File ~\Anaconda3\envs\plca_env\lib\multiprocessing\pool.py:364, in Pool.map(self, func, iterable, chunksize) 359 def map(self, func, iterable, chunksize=None): 360 ''' 361 Apply func to each element in iterable, collecting the results 362 in a list that is returned. 363 ''' --> 364 return self._map_async(func, iterable, mapstar, chunksize).get()

File ~\Anaconda3\envs\plca_env\lib\multiprocessing\pool.py:771, in ApplyResult.get(self, timeout) 769 return self._value 770 else: --> 771 raise self._value

File ~\Anaconda3\envs\plca_env\lib\multiprocessing\pool.py:125, in worker(inqueue, outqueue, initializer, initargs, maxtasks, wrap_exception) 123 job, i, func, args, kwds = task 124 try: --> 125 result = (True, func(*args, **kwds)) 126 except Exception as e: 127 if wrap_exception and func is not _helper_reraises_exception:

File ~\Anaconda3\envs\plca_env\lib\multiprocessing\pool.py:48, in mapstar(args) 47 def mapstar(args): ---> 48 return list(map(*args))

File ~\Anaconda3\envs\plca_env\lib\site-packages\premise\ecoinvent_modification.py:588, in NewDatabase.init.._fetch_iam_data(scenario) 587 def _fetch_iam_data(scenario): --> 588 data = IAMDataCollection( 589 model=scenario["model"], 590 pathway=scenario["pathway"], 591 year=scenario["year"], 592 external_scenarios=scenario.get("external scenarios"), 593 filepath_iam_files=scenario["filepath"], 594 key=key, 595 system_model=self.system_model, 596 system_model_args=self.system_model_args, 597 gains_scenario=self.gains_scenario, 598 use_absolute_efficiency=self.use_absolute_efficiency, 599 ) 600 scenario["iam data"] = data 602 if self.datapackages:

File ~\Anaconda3\envs\plca_env\lib\site-packages\premise\data_collection.py:399, in IAMDataCollection.init(self, model, pathway, year, filepath_iam_files, key, external_scenarios, system_model, system_model_args, gains_scenario, use_absolute_efficiency) 396 # flatten the list of lists 397 new_vars = flatten(new_vars) --> 399 data = self.__get_iam_data( 400 key=key, 401 filedir=filepath_iam_files, 402 variables=new_vars, 403 ) 405 self.regions = data.region.values.tolist() 406 self.system_model = system_model

File ~\Anaconda3\envs\plca_env\lib\site-packages\premise\data_collection.py:661, in IAMDataCollection.__get_iam_data(self, key, filedir, variables) 658 encrypted_data = file.read() 660 # decrypt data --> 661 decrypted_data = fernet_obj.decrypt(encrypted_data) 662 data = StringIO(str(decrypted_data, "latin-1")) 664 dataframe = pd.read_csv( 665 data, 666 sep=get_delimiter(data=copy.copy(data).readline()), 667 encoding="latin-1", 668 )

File ~\Anaconda3\envs\plca_env\lib\site-packages\cryptography\fernet.py:90, in Fernet.decrypt(self, token, ttl) 88 else: 89 time_info = (ttl, int(time.time())) ---> 90 return self._decrypt_data(data, timestamp, time_info)

File ~\Anaconda3\envs\plca_env\lib\site-packages\cryptography\fernet.py:151, in Fernet._decrypt_data(self, data, timestamp, time_info) 148 if current_time + _MAX_CLOCK_SKEW < timestamp: 149 raise InvalidToken --> 151 self._verify_signature(data) 153 iv = data[9:25] 154 ciphertext = data[25:-32]

File ~\Anaconda3\envs\plca_env\lib\site-packages\cryptography\fernet.py:130, in Fernet._verify_signature(self, data) 129 def _verify_signature(self, data: bytes) -> None: --> 130 h = HMAC(self._signing_key, hashes.SHA256()) 131 h.update(data[:-32]) 132 try:

File ~\Anaconda3\envs\plca_env\lib\site-packages\cryptography\hazmat\primitives\hmac.py:32, in HMAC.init(self, key, algorithm, backend, ctx) 30 self._key = key 31 if ctx is None: ---> 32 from cryptography.hazmat.backends.openssl.backend import ( 33 backend as ossl, 34 ) 36 self._ctx = ossl.create_hmac_ctx(key, self.algorithm) 37 else:

File ~\Anaconda3\envs\plca_env\lib\site-packages\cryptography\hazmat\backends\openssl__init.py:6 1 # This file is dual licensed under the terms of the Apache License, Version 2 # 2.0, and the BSD License. See the LICENSE file in the root of this repository 3 # for complete details. ----> 6 from cryptography.hazmat.backends.openssl.backend import backend 9 all__ = ["backend"]

File ~\Anaconda3\envs\plca_env\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py:63 56 from cryptography.hazmat.backends.openssl.x448 import ( 57 _X448PrivateKey, 58 _X448PublicKey, 59 ) 60 from cryptography.hazmat.bindings._rust import ( 61 x509 as rust_x509, 62 ) ---> 63 from cryptography.hazmat.bindings.openssl import binding 64 from cryptography.hazmat.primitives import hashes, serialization 65 from cryptography.hazmat.primitives._asymmetric import AsymmetricPadding

File ~\Anaconda3\envs\plca_env\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py:14 12 from cryptography import utils 13 from cryptography.exceptions import InternalError ---> 14 from cryptography.hazmat.bindings._openssl import ffi, lib 15 from cryptography.hazmat.bindings.openssl._conditional import CONDITIONAL_NAMES 17 _OpenSSLErrorWithText = typing.NamedTuple( 18 "_OpenSSLErrorWithText", 19 [("code", int), ("lib", int), ("reason", int), ("reason_text", bytes)], 20 )

ImportError: DLL load failed while importing _openssl: 找不到指定的模块。`

GemmaCC18 commented 11 months ago

One supplementary information: When only executing the command to import the package from premise import * from the beginning, it also sometimes throws the same error (ImportError: DLL load failed while importing _openssl), causing the package to not be imported correctly. But after trying a few more times, this import line of code can be imported smoothly.

romainsacchi commented 10 months ago

Sorry for the late answer. Tough one. Stupid question: after reinstalling openssl, have your restarted the kernel of your notebook?

romainsacchi commented 5 months ago

Closing the issue. Please re-open if the issue persists.