Python poetry throws error “Poetry could not find a
pyproject.toml file” when it is not able to find
pyproject.toml file in project directory. It means Poetry is not initialized properly.
If you are creating a new project then you will need to use this command –
poetry new poetry-demo
It will create the project in the current working directory. For example, I created a folder,
poetry-project in my
Downloads folder and ran this command –
This command will create
poetry-demo folder with these files –
The complete file structure looks like this –
poetry-demo ├── pyproject.toml ├── README.rst ├── poetry_demo │ └── __init__.py └── tests ├── __init__.py └── test_poetry_demo.py
You can see that we have
pyproject.toml file in this file structure. For now, this is the most important file and your poetry installation is not able to find it. That’s why it is throwing Poetry could not find a
pyproject.toml file error.
If you are adding Poetry in an existing project then you can run this command –
Most probably you are using poetry in your existing project and forgot to run
poetry init. If you follow this step, you error will resolve.
In this article we saw how we can resolve poetry could not find pyproject.toml file error by initializing the library properly. You can use poetry in new projects as well as your existing projects without any issues.