ImportError: cannot import name 'LegacyVersion' from 'packaging.version'

11.8k Views Asked by At

I am using python 3.10.6, and I installed pipenv, version 2022.12.19, I was planning to run a project using runway, so for this I created a folder, did the command pipenv --python 3.10, then updated in the pipfile to include runway, pip file is as follows:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
runway = "== 2.6.3"

[dev-packages]

[requires]
python_version = "3.10"
python_full_version = "3.10.6"

then I ran the command pipenv install, I was expecting runway to be there, but each time I try to run a command using runway I get this error:

ImportError: cannot import name 'LegacyVersion' from 'packaging.version' any idea?

3

There are 3 best solutions below

2
On

Try downgrading your 'packaging' to 21.3 instead of 22. This resolved the same issue for me (using runway).

I wish I could tell you where I found this, but honestly it's just rolling back the package version, due to the newest version missing something used by runway with it's terraform version validation. Downgrading the package is by no means a solution, but it's a band-aid for now.

This is outlined a bit at: https://github.com/onicagroup/runway/issues/1729, though Jake is using poetry instead of pipenv, it's very similar.

Example:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
runway = "*"
packaging = "==21.3"

[dev-packages]

[requires]
python_version = "3.10"
python_full_version = "3.10.6"

I do want to mention, I have done this band-aid with python3.7 and python3.8. The python version has a lot to do with it as well and I use 3.10 in my pyenv currently, I just haven't had a chance to do any new runway development lately (with python3.10 in the pipenv). I'll see if I can try it out when I have a new runway development though (I use runway a lot ❤️ ) and I'll do my best to follow up.

But by all means, post and let me know if my very first comment was at all helpful. :)

0
On

There might be a packaging issue with your environment.

pip install --upgrade --force-reinstall packaging

0
On

This issue will be resolved

pip install packaging==20.9