"env use" fails with "NameError: name 'PosixPath' is not defined"
See original GitHub issue-
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.
https://github.com/python-poetry/poetry/blob/d3c9049a18ae33baacfcb5c698777282f2f58128/poetry/utils/env.py#L625
Variable venv
is a Path
object, and it is finally passed to str.format()
https://github.com/python-poetry/poetry/blob/d3c9049a18ae33baacfcb5c698777282f2f58128/poetry/utils/env.py#L672
Then CREATE_VENV_COMMAND
is
https://github.com/python-poetry/poetry/blob/d3c9049a18ae33baacfcb5c698777282f2f58128/poetry/utils/env.py#L105-L106
$ 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 https://github.com/python-poetry/poetry/commit/54870697d921ae6efdbba0bc86f6b54c86d6896a
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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:10 (4 by maintainers)
I had the same issue, upgrading to the latest preview version fixed it for me - thanks!
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.