question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
  • [x ] I am on the latest Poetry version.

  • [x ] I have searched the issues of this repo and believe that this is not a duplicate.

  • [x ] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

  • OS version and name: Windows 10 Pro 21H1

  • Poetry version: 1.1.13

  • Link of a Gist with the contents of your pyproject.toml file: pyproject.toml

Issue

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

My environment:

  • Python 3.8 installed in C:\Python38 and in PATH environment variable
  • Python 3.7 installed in C:\Python37
  • Use VSCode

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

  • Python 3.8 installed in C:\Python38
  • Python 3.7 installed in C:\Python37
  • PATH = …C:\Python38\Scripts;C:\Python38…
  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!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
timthedevguycommented, May 9, 2022

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!

0reactions
abncommented, May 9, 2022

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/.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error on pipenv install: AttributeError: 'PathDistribution' object ...
AttributeError : 'PathDistribution' object has no attribute '_normalized_name' ✘ Failed creating virtual environment [pipenv.exceptions.
Read more >
AttributeError: 'PathDistribution' object has no attribute 'name'
I am using chain to sequentially run the tasks, with following workflow. Extract a file, tokenize it and load JSON dumps of sentence...
Read more >
'PathDistribution' object has no attribute 'entry_points' - Unity ...
AttributeError : 'PathDistribution' object has no attribute 'entry_points' In fact, the same error happened when I tried on Release 12.
Read more >
FS#73019 : [salt] AttributeError: 'PathDistribution' object has ...
FS#73019 - [salt] AttributeError: 'PathDistribution' object has no attribute '_normalized_name'. Attached to Project: Community Packages
Read more >
importlib.metadata — Runway v2.6.3
Otherwise, return the named object. ... config.read_string(text) except AttributeError: # pragma: nocover # Python 2 has no read_string config.readfp(io.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found