netrep
netrep copied to clipboard
Fails on Python 3.7, can't import Literal from typing
Recently had to downgrade Python to 3.7 for some reason and ran into this.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~/code/netrep/netrep/metrics/__init__.py in <module>
1 from netrep.metrics.cka import LinearCKA
----> 2 from netrep.metrics.linear import LinearMetric
3 from netrep.metrics.perm import PermutationMetric
4 from netrep.metrics.stochastic import GaussianStochasticMetric
5 from netrep.metrics.stochastic import EnergyStochasticMetric
~/code/netrep/netrep/metrics/linear.py in <module>
1 from __future__ import annotations
----> 2 from typing import Literal, Tuple
3
4 import numpy as np
5 import numpy.typing as npt
ImportError: cannot import name 'Literal' from 'typing' (/mnt/home/awilliams/anaconda3/envs/allensdk/lib/python3.7/typing.py)
We should specify our requirements better, or figure out a way to support Python 3.7
You'll need to add typing_extensions
to your deps, and then:
try:
from typing import Literal
except ImportError:
from typing_extensions import Literal
Ref: https://stackoverflow.com/a/67193166/1939934