``poetry new`` fails when creating a new system environment
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 Version 21H1 (OS Build 19043.1415)
- Poetry version: 1.1.12
- Python version: Python 3.9.9 (installed via Windows store)
- Link of a Gist with the contents of your pyproject.toml file: N/A
Issue
When I run poetry new {name}
, i get the following OSError (full traceback from poetry new {name} -vvv
here:
OSError
[WinError 1920] The file cannot be accessed by the system: 'C:\\Users\\yngve.moe\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\python.exe\\Scripts'
at C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\pathlib.py:1232 in stat
1228│
1229│ Return the result of the stat() system call on this path, like
1230│ os.stat() does.
1231│ """
→ 1232│ return self._accessor.stat(self)
1233│
1234│ def owner(self):
1235│
1236│ Return the login name of the file owner.
I’ve done some debugging, and it seems like the bug is due to the following lines (at time of writing, commit e34277e):
This line creates a new system environment with the path to the python.exe executable (C:\\Users\\yngve.moe\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\python.exe
)
https://github.com/python-poetry/poetry/blob/e34277e24026d80bc88898a5710183383686962f/src/poetry/console/commands/new.py#L66
Then, the self._bin_dir
is set to the path to the Python executable (not its parent directory)
https://github.com/python-poetry/poetry/blob/e34277e24026d80bc88898a5710183383686962f/src/poetry/utils/env.py#L1082
The next problem arises during this function call: https://github.com/python-poetry/poetry/blob/e34277e24026d80bc88898a5710183383686962f/src/poetry/utils/env.py#L1087
Specifically, it happens on this line, since self._bin_dir.glob
is the path to the Python executable, not its parent directory.
https://github.com/python-poetry/poetry/blob/e34277e24026d80bc88898a5710183383686962f/src/poetry/utils/env.py#L1139
I am able to circumvent this problem locally by modifying https://github.com/python-poetry/poetry/blob/e34277e24026d80bc88898a5710183383686962f/src/poetry/console/commands/new.py#L66 to be
current_env = SystemEnv(Path(sys.executable).parent)
EDIT: I am relatively certain that there is something with my Windows setup that leads to this problem, since I have been able to get Poetry to work with Miniconda (which I have uninstalled now) on the same computer before, but I’ll leave this issue open since it should work with the installation from Windows store too.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:14
I uninstalled Python from Windows store, and reinstalled it via the installer I downloaded from https://www.python.org/downloads/release/python-3102/, then the issue resolved. I suspect it has something with the Windows store version of Python.
Same problem here, with
poetry init
This generally seems to happen when you install python via the Windows Store installer. In my case installing with the python.org installer is a little tricky because I’m not an adminstrator on the machine in questionpoetry/src/poetry/utils/env.py I think it is because
SystemEnv
calls theEnv
constructor wich appends/Scripts
to the path it gets viasys.executable
on Windows. The problem is the resulting path just does not exist. There is noScripts
directory.This seems to work for the python.org installer but the Store installer seems to layout the directory structure a little differently.