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.

``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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:14

github_iconTop GitHub Comments

3reactions
xiefangggcommented, Mar 16, 2022

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.

1reaction
GotFlojocommented, Apr 8, 2022

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 question

poetry/src/poetry/utils/env.py I think it is because SystemEnv calls the Env constructor wich appends /Scripts to the path it gets via sys.executable on Windows. The problem is the resulting path just does not exist. There is no Scripts directory.

This seems to work for the python.org installer but the Store installer seems to layout the directory structure a little differently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

History | Poetry - Python dependency management and ...
Fix an issue where experimental.system-git-client could not be used via environment variable (#6783). Fix an issue where Poetry fails with an AssertionError ......
Read more >
Configure a Pipenv environment | PyCharm Documentation
Select Pipenv when creating a new Python project. In the left-hand pane of the Add Python Interpreter dialog, select Pipenv Environment.
Read more >
How To Install Poetry to Manage Python Dependencies on ...
Start by creating a new Poetry project. This project will come with the virtual environment that will be used when installing and managing ......
Read more >
A Poetic Apology. Or Why Should You Use Poetry to Manage…
A new data.py run however now, unfortunately, shows the next error ... python = "^3.7"[tool.poetry.dev-dependencies][build-system]
Read more >
Integrating Python Poetry with Docker - Stack Overflow
In short, install Poetry, let Poetry create the virtual environment, then enter the virtual environment every time you start a new shell by...
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