python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.9k stars 2.28k forks source link

AttributeError: 'PathDistribution' object has no attribute '_normalized_name' #5583

Closed timthedevguy closed 2 years ago

timthedevguy commented 2 years ago

Issue

I have been able to reproduce this repeatedly. (Steps at bottom)

My environment:

For this project I needed to use Python 3.7, so I specified '^3.7' for Python version and then used poetry env use C:\Python37\python.exe which creates the env successfully.

Running any poetry command (even poetry by itself) results in the following output but ONLY when I'm in the activated env. Outside of the env Poetry is fine.

(allianceauth-dev-Yhucgjl3-py3.7) PS C:\Users\tim.davis\Projects\Python\allianceauth-dev> poetry
Traceback (most recent call last):
  File "C:\Users\tim.davis\.poetry\bin\poetry", line 17, in <module>
    from poetry.console import main
  File "C:\Users\tim.davis\.poetry\lib\poetry\console\__init__.py", line 1, in <module>
    from .application import Application
  File "C:\Users\tim.davis\.poetry\lib\poetry\console\application.py", line 7, in <module>
    from .commands.about import AboutCommand
  File "C:\Users\tim.davis\.poetry\lib\poetry\console\commands\__init__.py", line 4, in <module>    
    from .check import CheckCommand
  File "C:\Users\tim.davis\.poetry\lib\poetry\console\commands\check.py", line 2, in <module>       
    from poetry.factory import Factory
  File "C:\Users\tim.davis\.poetry\lib\poetry\factory.py", line 18, in <module>
    from .repositories.pypi_repository import PyPiRepository
  File "C:\Users\tim.davis\.poetry\lib\poetry\repositories\pypi_repository.py", line 33, in <module>
    from ..inspection.info import PackageInfo
  File "C:\Users\tim.davis\.poetry\lib\poetry\inspection\info.py", line 25, in <module>
    from poetry.utils.env import EnvCommandError
  File "C:\Users\tim.davis\.poetry\lib\poetry\utils\env.py", line 23, in <module>
    import virtualenv
  File "C:\Users\tim.davis\.poetry\lib\poetry\_vendor\py3.7\virtualenv\__init__.py", line 3, in <module>
    from .run import cli_run, session_via_cli
  File "C:\Users\tim.davis\.poetry\lib\poetry\_vendor\py3.7\virtualenv\run\__init__.py", line 14, in <module>
    from .plugin.creators import CreatorSelector
  File "C:\Users\tim.davis\.poetry\lib\poetry\_vendor\py3.7\virtualenv\run\plugin\creators.py", line 6, in <module>
    from virtualenv.create.via_global_ref.builtin.builtin_way import VirtualenvBuiltin
  File "C:\Users\tim.davis\.poetry\lib\poetry\_vendor\py3.7\virtualenv\create\via_global_ref\builtin\builtin_way.py", line 7, in <module>
    from virtualenv.create.creator import Creator
  File "C:\Users\tim.davis\.poetry\lib\poetry\_vendor\py3.7\virtualenv\create\creator.py", line 15, in <module>
    from virtualenv.discovery.cached_py_info import LogCmd
  File "C:\Users\tim.davis\.poetry\lib\poetry\_vendor\py3.7\virtualenv\discovery\cached_py_info.py", line 23, in <module>
    _CACHE[Path(sys.executable)] = PythonInfo()
  File "C:\Users\tim.davis\.poetry\lib\poetry\_vendor\py3.7\virtualenv\discovery\py_info.py", line 86, in __init__
    self.distutils_install = {u(k): u(v) for k, v in self._distutils_install().items()}
  File "C:\Users\tim.davis\.poetry\lib\poetry\_vendor\py3.7\virtualenv\discovery\py_info.py", line 152, in _distutils_install
    d = dist.Distribution({"script_args": "--no-user-cfg"})  # conf files not parsed so they do not hijack paths
  File "C:\Users\tim.davis\AppData\Local\pypoetry\Cache\virtualenvs\allianceauth-dev-Yhucgjl3-py3.7\lib\site-packages\setuptools\dist.py", line 456, in __init__  
    for ep in metadata.entry_points(group='distutils.setup_keywords'):
  File "C:\Users\tim.davis\AppData\Local\pypoetry\Cache\virtualenvs\allianceauth-dev-Yhucgjl3-py3.7\lib\site-packages\setuptools\_vendor\importlib_metadata\__init__.py", line 1003, in entry_points
    return SelectableGroups.load(eps).select(**params)
  File "C:\Users\tim.davis\AppData\Local\pypoetry\Cache\virtualenvs\allianceauth-dev-Yhucgjl3-py3.7\lib\site-packages\setuptools\_vendor\importlib_metadata\__init__.py", line 453, in load
    ordered = sorted(eps, key=by_group)
  File "C:\Users\tim.davis\AppData\Local\pypoetry\Cache\virtualenvs\allianceauth-dev-Yhucgjl3-py3.7\lib\site-packages\setuptools\_vendor\importlib_metadata\__init__.py", line 1001, in <genexpr>
    dist.entry_points for dist in unique(distributions())
  File "C:\Users\tim.davis\AppData\Local\pypoetry\Cache\virtualenvs\allianceauth-dev-Yhucgjl3-py3.7\lib\site-packages\setuptools\_vendor\importlib_metadata\_itertools.py", line 16, in unique_everseen
    k = key(element)
AttributeError: 'PathDistribution' object has no attribute '_normalized_name'

To Reproduce

  1. Create new Folder and navigate to folder in Cmd or PowerShell
  2. Run poetry init and provide Python version of '^3.7' when prompted, I do not define dependencies interactively
  3. Run poetry env use C:\Python37\python.exe
  4. Run poetry shell
  5. Run poetry which should print out help, instead I get the error

I can run this procedure on a Python 3.8 project and not have the error so I'm guessing something to do with 3.7...but I could be wrong.

Thanks for reading!

abn commented 2 years ago

The issue looks like it's that specific virtual environment. I'd try re-creating it.

timthedevguy commented 2 years ago

I have recreated it in multiple places, different folders, different parent folders, I can run the 'Steps to Reproduce' anywhere and have it happen.

timthedevguy commented 2 years ago

You can see a video of the error happening here, brand new folder on Desktop that has never been used before...I create it in the video. Poetry Error

abn commented 2 years ago

Does the same issue happen if you activate the environment via C:\Users\tim.davis\AppData\Local\pypoetry\Cache\virtualenvs\allianceauth-dev-Yhucgjl3-py3.7\Scripts/activate.bat oppposed to poetry shell?

That said, I have a sneaky suspicion the issue the vendored version of virtualenv in your system (https://github.com/pypa/virtualenv/pull/2246). I'd recommend that you try uninstalling your current install (using the old installer) and installing via the new installer or pipx.

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python - --uninstall
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -

You can see the new installation doc at https://python-poetry.org/docs/master/.

timthedevguy commented 2 years ago

If I use the activate.bat then it works successfully.

And the uninstall and reinstall did the trick....I was using the docs located at https://python-poetry.org/docs/, my apologies and much thanks for the quick assistance!

github-actions[bot] commented 9 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.