poetry env use fails with NameError: name 'WindowsPath' 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: Windows 10 Pro
- Poetry version: 1.0.10
- Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/moochannel/f26598d0d763cbadd7ca44e89bc917c0
Issue
When I run poetry env use "C:\Program Files\Python37\python.exe"
in a directory without a virtual environment, it fails with NameError: name 'WindowsPath' is not defined
.
(In empty directory C:\Users\xxxx\poetrytest)
> poetry init
> poetry env use "C:\Program Files\Python37\python.exe"
Creating virtualenv poetrytest in C:\Users\xxxx\poetrytest\.venv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'WindowsPath' is not defined
[EnvCommandError]
Command ['python', '-'] errored with the following return code 1, and output:
'python' is not recognized as an internal or external command,
operable program or batch file.
input was : import sys
if hasattr(sys, "real_prefix"):
print(sys.real_prefix)
elif hasattr(sys, "base_prefix"):
print(sys.base_prefix)
else:
print(sys.prefix)
exit status 1
CREATE_VENV_COMMAND.format(path))
in EnvManager.build_venv converts path
to WindowsPath(path)
, but CREATE_VENV_COMMAND doesn’t contain pathlib.WindowsPath. So it results in an error.
My workaround here. I suppose the path
should be converted from WindowsPath to str before it passed to CREATE_VENV_COMMAND.format(path))
.
--- env.py.bak 2020-07-22 06:30:05.245529100 +0900
+++ env.py 2020-07-22 14:20:24.012698600 +0900
@@ -669,7 +669,7 @@
stdin=subprocess.PIPE,
shell=True,
)
- p.communicate(encode(CREATE_VENV_COMMAND.format(path)))
+ p.communicate(encode(CREATE_VENV_COMMAND.format(str(path))))
except CalledProcessError as e:
raise EnvCommandError(e)
After patching this, the command runs fine.
> poetry env use "C:\Program Files\Python37\python.exe"
Creating virtualenv poetrytest in C:\Users\xxxx\poetrytest\.venv
Using virtualenv: C:\Users\xxxx\poetrytest\.venv
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
What is the default install path for poetry - Stack Overflow
I saw it was installed using my local Python and not linked to a conda environment. In my case I added export PATH="$HOME/.local/bin:$PATH"....
Read more >Configure a Poetry environment that runs in PyCharm
Poetry is a wonderful open-source tool that can ease the pain of setting up your environment and configuring its dependencies. In this blog,...
Read more >Using Python's pip to Manage Your Projects' Dependencies
Here you create a virtual environment named venv by using Python's built-in venv module. Then you activate it with the source command.
Read more >Python Tools for Managing Virtual Environments
Poetry. Set Poetry virtual environment location; Interacting with the Poetry ... As seen above, I usually use the name .venv or, for more ......
Read more >Configure a Pipenv environment | PyCharm Documentation
After the preparation steps are done, you can use pipenv to create a virtual environment for new or existing projects. Set pipenv for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Followup: the newest version requires the syntax “poetry self update --preview” in order to work, but even at that it denies permission even if PowerShell runs with administrator access. Every time it gets really close to upgrading but it always runs into a file where access is denied. I’ll keep exploring but so far it looks like uninstalling the current version of poetry and then downloading the desired version might be the best workaround. If anyone knows of a better solution please let me know. Thanks!
@abn Thank you for your quick reply. I tried the develop branch with
pip install git+https://github.com/python-poetry/poetry.git@develop
. The problem has been gone😉Since
poetry -V
shows as 1.1.0a3 in the develop branch, I think this will be fixed in the next 1.1.0x release. Will this change apply to 1.0.x?