DEV Community

codegabru
codegabru

Posted on

5

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.

Image of Bright Data

Global Data Access Unlocked – Reach data across borders without restrictions.

Unlock the power of global data collection with our advanced proxy solutions. Ideal for market research and more.

Unlock Data Now

Top comments (1)

Collapse
 
jjlorenzo profile image
jjlorenzo

I use pyenv and direnv without needing this fix

Image of Bright Data

Feed Your Models Real-Time Data – Enhance your AI with up-to-the-minute data.

Utilize our live data feeds for dynamic model training, ensuring your AI systems are always ahead.

Access Real-Time Data