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.

"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:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

43reactions
alexloudencommented, 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
11reactions
tonycommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't start Python - ImportError: No module named posixpath
This only happens within virtualenv. I can start global Python without problem. My server (using Linode) wasn't restarted recently and as far as ......
Read more >
posixpath -- Python library reference
This module implements some useful functions on POSIX pathnames. basename ( p ) -- function of module posixpath: Return the base name of...
Read more >
11.1. pathlib — Object-oriented filesystem paths
Source code: Lib/pathlib.py. This module offers classes representing filesystem paths with semantics appropriate for different operating systems.
Read more >
Python 2.1 Quick Reference
Python identifiers keywords, attributes, etc. are case-sensitive. Special forms: _ident (not imported by 'from module import *'); __ident__ (system defined name);
Read more >
Python Path – How to Use the Pathlib Module with Examples
Pathlib contains many objects such as PosixPath() and PurePath() ... You will not get any error if you instantiate PurePosixPath() on ...
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