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

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

Closed
3 tasks done
elferia opened this issue Jul 24, 2020 · 11 comments · Fixed by #2666
Closed
3 tasks done

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

elferia opened this issue Jul 24, 2020 · 11 comments · Fixed by #2666
Labels
kind/bug Something isn't working as expected

Comments

@elferia
Copy link

elferia commented Jul 24, 2020

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

@elferia elferia added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jul 24, 2020
@elferia
Copy link
Author

elferia commented Jul 24, 2020

version 1.1.0a3 not include 5487069

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

So workaround is installing preview version.

@abn
Copy link
Member

abn commented Jul 24, 2020

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

@abn abn removed the status/triage This issue needs to be triaged label Jul 24, 2020
@abn abn linked a pull request Jul 24, 2020 that will close this issue
1 task
@abn abn closed this as completed Jul 24, 2020
@alexlouden
Copy link

alexlouden commented Jul 26, 2020

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

@tony
Copy link
Contributor

tony commented Jul 26, 2020

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.

@goodcheer
Copy link

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)

@jrgoldfinemiddleton
Copy link

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

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

@gavinbeatty
Copy link

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

@abn
Copy link
Member

abn commented Sep 29, 2020

@languitar
Copy link

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.

@tony
Copy link
Contributor

tony commented Jan 30, 2021

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

Copy link

github-actions bot commented Mar 2, 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 2, 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

Successfully merging a pull request may close this issue.

8 participants