Skip to content

"env use" fails with "NameError: name 'PosixPath' is not defined" #2711

Closed

Description

@elferia
  • I am on the latest Poetry version.

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

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

  • OS version and name: Ubuntu 18.04.4 LTS

  • Poetry version: 1.0.10

Issue

When I try the following command,

poetry env use 3.8

it will fail with the following message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'PosixPath' is not defined

I guess this is caused by the following line.

self.build_venv(venv, executable=executable)

Variable venv is a Path object, and it is finally passed to str.format()
p.communicate(encode(CREATE_VENV_COMMAND.format(path)))

Then CREATE_VENV_COMMAND is

poetry/poetry/utils/env.py

Lines 105 to 106 in d3c9049

CREATE_VENV_COMMAND = """\
path = {!r}

$ python -c 'import pathlib; print("{!r}".format(pathlib.Path("/")))'
PosixPath('/')

So the interpreter will first read a line like path = PosixPath('...') but PosixPath is not defined.

I think this bug is introduced in 1.0.10 5487069

I guess it will be fixed by replacing venv to str(venv) so I tried to fix, but the commit above is replacing str(venv) to venv and I can't understand the purpose to do so. I can't fix it.

Thanks.

Activity

  1. added
    kind/bugSomething isn't working as expected
    status/triageThis issue needs to be triaged
    on Jul 24, 2020
  2. elferia commented on Jul 24, 2020

    @elferia
    Author

    version 1.1.0a3 not include 5487069

    self.build_venv(str(venv), executable=executable)

    So workaround is installing preview version.

  3. abn commented on Jul 24, 2020

    @abn
    Member

    @elferia appreciate the bug report and the analysis. As you have already identified, the preview version will resolve this. And since we recently released the last 1.0.z release and next release is expected soon, resolving this.

  4. linked a pull request that will close this issueStandardise on using virtualenv package #2666on Jul 24, 2020
  5. alexlouden commented on Jul 26, 2020

    @alexlouden

    I had the same issue, upgrading to the latest preview version fixed it for me - thanks!

    $ poetry self update --preview
    Updating to 1.1.0b2
    
  6. tony commented on Jul 26, 2020

    @tony
    Contributor

    Thanks @alexlouden

    I had to do : pip install --user --pre poetry -U

    Since my poetry installation gave me this warning: Poetry was not installed with the recommended installer. Cannot update automatically.

  7. goodcheer commented on Jul 28, 2020

    @goodcheer

    Thanks @tony

    if you're using pipx as install manager, you can get pre-release by : pipx install --pip-args='--pre' poetry (confimred working)

    or upgrade exisiting one pipx install --pip-args='--pre -U' poetry (haven't tried this one, but might work)

  8. added a commit that references this issue on Aug 4, 2020
  9. added a commit that references this issue on Aug 15, 2020
  10. jrgoldfinemiddleton commented on Sep 5, 2020

    @jrgoldfinemiddleton

    pipx install --pip-args='--pre -U' poetry

    I had to use this instead:
    pipx upgrade --pip-args='--pre' poetry

  11. added a commit that references this issue on Sep 18, 2020
  12. gavinbeatty commented on Sep 29, 2020

    @gavinbeatty

    Still running into this issue when doing poetry shell on mac latest stable, works on preview 1.1.0rc1.

  13. abn commented on Sep 29, 2020

    @abn
    Member
  14. languitar commented on Jan 7, 2021

    @languitar

    Isn't there a chance to get a patch release for this bug for the 1.0 line? Seems a few dependencies still block upgrading things like the archlinux package and user there are then stuck with this broken version.

  15. tony commented on Jan 30, 2021

    @tony
    Contributor

    @abn Hi there! I got a a question (echo'ing) @languitar at #2711 (comment)

    Is there any way around this upgrading to 1.1 (I can't do that - I have projects depending on 1.0 and it's the team's choice whether poetry upgrades, the lockfiles aren't compatible to my knowledge between 1.0 and 1.1)

    Is this something that could be backported into 1.0? (I am on 1.0.10)

    What was the fix for this in 1.1? Is it a trivial one?

    I don't believe it's solved by 5487069, which is in 1.0.10, since I still get the issue. The PR at #2742 doesn't specify what change fixed it in 1.1 at the time

    Any workarounds aside from upgrading anyone know of? This sorta breaks my setup.

  16. github-actions commented on Mar 2, 2024

    @github-actions

    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.

  17. locked as resolved and limited conversation to collaborators on Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions