Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
timthedevguy opened this issue May 9, 2022 · 6 comments
Labels
kind/bug Something isn't working as expected

Comments

@timthedevguy
Copy link

timthedevguy commented May 9, 2022

  • [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!

@timthedevguy timthedevguy added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels May 9, 2022
@abn
Copy link
Member

abn commented May 9, 2022

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

@timthedevguy
Copy link
Author

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
Copy link
Author

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
Copy link
Member

abn commented 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 (pypa/virtualenv#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.github.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
Copy link
Author

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!

@mkniewallner mkniewallner removed the status/triage This issue needs to be triaged label Jun 11, 2022
Copy link

github-actions bot commented Mar 1, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

3 participants