python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.69k stars 2.27k forks source link

Poetry init OSError on windows 10 #4667

Open NujanZh opened 3 years ago

NujanZh commented 3 years ago

Issue

I type poetry init and it give me this error: ` [WinError 1920] Доступ к этому файлу из системы отсутствует (Translate: this file cannot be accessed from the system.): 'C:\Users\*****\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\python.exe\Scripts'

at C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\pathlib.py:1198 in stat 1194│ 1195│ Return the result of the stat() system call on this path, like 1196│ os.stat() does. 1197│ """ → 1198│ return self._accessor.stat(self) 1199│ 1200│ def owner(self): 1201│ 1202│ Return the login name of the file owner.

`

roslovets commented 3 years ago

The same error in Windows 11 for Python 3.9 installed via Windows Store.

noi4eg commented 3 years ago

same error win10 for Python 3.9 and 3.10 installed via WS

Fethi-Hamdani commented 2 years ago

same error

new-divos commented 2 years ago

same error

spavett commented 2 years ago

same error:

Win 11 python 3.9 from windows store poetry 1.1.12 installed via powershell

I was trying to run the init through pycharm which gives some traceback:

[WinError 1920] The file cannot be accessed by the system: 'C:\Users\steve\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

Traceback (most recent call last): File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\console_application.py", line 131, in run status_code = command.handle(parsed_args, io) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\api\command\command.py", line 120, in handle status_code = self._do_handle(args, io) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\api\command\command.py", line 171, in _do_handle return getattr(handler, handler_method)(args, io, self) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\cleo\commands\command.py", line 92, in wrap_handle return self.handle() File "C:\Users\steve.poetry\lib\poetry\console\commands\init.py", line 144, in handle current_env = SystemEnv(Path(sys.executable)) File "C:\Users\steve.poetry\lib\poetry\utils\env.py", line 936, in init self.find_executables() File "C:\Users\steve.poetry\lib\poetry\utils\env.py", line 1080, in find_executables [ File "C:\Users\steve.poetry\lib\poetry\utils\env.py", line 1080, in [ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64qbz5n2kfra8p0\lib\pathlib.py", line 1177, in glob for p in selector.select_from(self): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\pathlib.py", line 523, in select_from if not is_dir(parent_path): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64qbz5n2kfra8p0\lib\pathlib.py", line 1439, in is_dir return S_ISDIR(self.stat().st_mode) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\pathlib.py", line 1232, in stat return self._accessor.stat(self) OSError: [WinError 1920] The file cannot be accessed by the system: 'C:\Users\steve\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe\Scripts'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\steve.poetry\bin\poetry", line 19, in main() File "C:\Users\steve.poetry\lib\poetry\console__init.py", line 5, in main return Application().run() File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\console_application.py", line 142, in run trace.render(io, simple=isinstance(e, CliKitException)) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\ui\components\exception_trace.py", line 232, in render return self._render_exception(io, self._exception) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\ui\components\exception_trace.py", line 269, in _render_exception self._render_snippet(io, current_frame) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\ui\components\exception_trace.py", line 289, in _render_snippet self._render_line(io, code_line) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\ui\components\exception_trace.py", line 402, in _render_line io.write_line("{}{}".format(indent * " ", line)) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\cleo\io\io_mixin.py", line 65, in write_line super(IOMixin, self).write_line(string, flags) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\api\io\io.py", line 66, in write_line self._output.write_line(string, flags=flags) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\api\io\output.py", line 69, in write_line self.write(string, flags=flags, new_line=True) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\api\io\output.py", line 61, in write self._stream.write(to_str(formatted)) File "C:\Users\steve.poetry\lib\poetry_vendor\py3.9\clikit\io\output_stream\stream_output_stream.py", line 24, in write self._stream.write(string) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64qbz5n2kfra8p0\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u2502' in position 10: character maps to

clintonroy commented 2 years ago

So...i'm not a windows person at all..so i'll just forget that.

Does the file exist? Can you..open it as a regular user? Can you maybe try as an admin user?

spavett commented 2 years ago

@clintonroy the path that was being opened looks like it's been concatenated from an environment property that included the name of the python executable and "\Scripts" - the path doesn't exist.

C:\Users\steve\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe\Scripts

I suspect the first part of the path is not what was expected in the poetry code and is a side effect of the way the MSStore installs python.

Note that removing the MSStore version of python and replacing with the python for windows version from python.org resulted in poetry working for me just now.

spavett commented 2 years ago

Forgot to say I had to change the launch batch file %USERPROFILE%.poetry\bin\poetry.bat as it was trying to run python3 which I guess is again a side effect of installing from the MS Store. I changed it to run python

python "%USERPROFILE%\.poetry\bin\poetry" %*

Hope that helps anyone who ended up here. Windows pushes you towards the MS store version via winget but you can install the python.org version via winget as well. It just downloads the installer so there isn't really a difference between using winget and running the installer manually as far as I know.

ghost commented 2 years ago

The thing is that I uninstalled MS python, but know that I have the python org version, poetry installation is not being recognized and I have no way to uninstall poetry... any idea.

ambowater commented 2 years ago

Has the poetry team looked at the issue? Basically the recommended python install on windows 10/11 via the store is not compatible with Poetry. easiest solution is to install python via the official website. Note: uninstall script is also ko.

"poetry new poetry-demo" --> OSError

[WinError 1920] The file cannot be accessed by the system: 'C:\Users\xxxxxx\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe\Scripts'

at C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.752.0_x64__qbz5n2kfra8p0\lib\pathlib.py:1095 in stat 1091│ 1092│ Return the result of the stat() system call on this path, like 1093│ os.stat() does. 1094│ """ → 1095│ return self._accessor.stat(self, follow_symlinks=follow_symlinks) 1096│ 1097│ def owner(self): 1098│ 1099│ Return the login name of the file owner.

ghost commented 2 years ago

At the end I had to uninstall poetry manually I searched all related files and erased them and installed again. I don't know if that could have a negative effect or lead to future mistakes, but so far, I haven't had any issue with my latest Poetry installation. I installed poetry with the cmd line from the official Poetry documentation.

liudonghua123 commented 2 years ago

I have uninstalled ms store verison of python and changed %USERPROFILE%.poetry\bin\poetry.bat as mentioned in https://github.com/python-poetry/poetry/issues/4667#issuecomment-997732616.

AM-I-Human commented 2 years ago

I resolved by installing poetry with pipx. I hope that helps. :) I have the Windows Store python 3.10.4 version

veenstrajelmer commented 4 weeks ago

I got a similar error ('charmap' codec can't encode character '\U0001f40d' in position 68: character maps to <undefined> ) when using poetry show on github, it broke right before the line of the mergedeep package, because of the snake in description = "A deep merge function for 🐍.". It might be related so I though tot share