Poetry Project in Pycharm with Python 3.12.5
How to create Poetry Project in PyCharm?
- In PyCharm Terminal , go to specific directory and and type command - ‘poetry new Project-Name’
- cd into Project directory - ‘cd Project-Name’
- Inside project folder, now add poetry using command - ‘poetry env use python3’
- Poetry which Python version to use ‘poetry env use python3’
- If you have created a venv (virtual enviorment) using Interpreter option of PyCharm make sure to use that venv
- If Poetry is still giving the error, you can manually activate the virtual environment, ‘source .venv/bin/activate’
- Validate the path of active venv using ‘poetry env info –path’. This same path must be selected as Interpreter under Pythorm settings . If not make sure to modify it and add path by Selecting the python executable within the .venv/bin/ directory
- Then run ‘poetry install’
- Check python version in terminal if its the same one you set from venv ‘python3 –version’
- Finally you are ready to run your project , use command - ‘poetry run python
/ .py'
Note: When you observe a red marks on python package imports, even after adding it via poetry then make sure to validate venv paths and interpreter path is the same.