DEV Community

codegabru
codegabru

Posted on

Using Python 3 with Poetry

This was originally posted on my Hashnode blog.

Install Poetry:

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3

The only problem is that for some reason Poetry doesn’t use Python version 3 by default for any project that you create using it and it doesn't run virtual environment shell using Python 3 even if the min required version of python is set to 3.x for the project. See issue for more details.

A quick, safe and dirty (because you will have to do this every time you update Poetry version) way to fix this is given below.

Open ~/.poetry/bin/poetry in editor of your choice. I’ll use nano :

nano ~/.poetry/bin/poetry

Top line of the file will be:

#!/usr/bin/env python

Update it to:

#!/usr/bin/env python3

Now Poetry should work as expected i.e run virtual environment shell using Python 3 etc.

Note: I think this will probably break things when you set min required version of Python to 2.x for your project. I have not tested this for Python 2. Python 2 has been deprecated anyway. Let me know in the comments if there is a better way to do it.

Top comments (1)

Collapse
 
jjlorenzo profile image
jjlorenzo

I use pyenv and direnv without needing this fix