Search code examples
pythonpython-poetrytoml

poetry [EnvCommandError] Fatal Python error: Py_Initialize: can't initialize sys standard streams


I have a pyproject.toml file that was created using poetry, and I'm trying to run the command poetry install in this directory to create a poetry.lock file. However, when I run poetry install, I get the following error:

  EnvCommandError

  Command C:\Users\myName\AppData\Local\pypoetry\Cache\virtualenvs\my-app-name-kS94etse-py3.8\Scripts\python.exe - 
  errored with the following return code 3, and output:
      Fatal Python error: Py_Initialize: can't initialize sys standard streams
      Traceback (most recent call last):
        File "c:\users\myName\anaconda3\lib\io.py", line 52, in <module>
        File "c:\users\myName\anaconda3\lib\abc.py", line 106
          print(f"Class: {cls.__module__}.{cls.__qualname__}", file=file)
                                                            ^
      SyntaxError: invalid syntax
      input was : import sys

This error seems pretty in depth but I dont understand why poetry thinks import sys is invalid syntax or even where that's being called to create an issue. Any suggestions on how to fix this?


Solution

  • Resolved here: https://stackoverflow.com/a/67169273/12060361

    1. Download a new, non-broken version of Python (the same version defined in your pyproject.toml file to use): https://www.python.org/downloads/release/python-385/
    2. Navigate to the virtual env folder poetry says the error is coming from: C:\Users\myName\AppData\Local\pypoetry\Cache\virtualenvs\my-app-name-kS94etse-py3.8\Scripts\python.exe
    3. Replace the python.exe currently in that folder with the new one you just downloaded