Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poetry default to using python instead of python3 #3184

Closed
2 tasks done
yunti opened this issue Oct 12, 2020 · 9 comments
Closed
2 tasks done

poetry default to using python instead of python3 #3184

yunti opened this issue Oct 12, 2020 · 9 comments
Labels
kind/bug Something isn't working as expected

Comments

@yunti
Copy link

yunti commented Oct 12, 2020

  • I am on the latest Poetry version.

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • [n/a ] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

  • OS version and name: macOS big sur

  • Poetry version: 1.1.2

  • python3.8 installed with home-brew

Issue

when creating a new project with poetry it sets the python version as python 2.7 by default rather than using the latest available version.

It also ironically prints the warning:

Python 2.7 will no longer be supported in the next feature release of Poetry (1.2).
You should consider updating your Python version to a supported one.

Note that you will still be able to manage Python 2.7 projects by using the env command.
See https://python-poetry.org/docs/managing-environments/ for more information.
@yunti yunti added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Oct 12, 2020
@pedrorrivero
Copy link

It also fails to create the virtual environment. My current config is as follows:

cache-dir = "~/Library/Caches/pypoetry"
experimental.new-installer = true
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.path = "{cache-dir}/virtualenvs"  # ~/Library/Caches/pypoetry/virtualenvs

@ericriff
Copy link

ericriff commented Oct 13, 2020

The issue here is that the poetry executable has python in its shebang, which is annoying.
I don't remember exactly where it gets installed, but lets say it is /usr/bin/poetry, you can get this path with $ which poetry. If you edit the shebang in that executable and replace it with !/usr/bin/env python3 instead of !/usr/bin/env python it will work.

This is a hack and not a solution. I don't know why this is not the default behavior.

@finswimmer
Copy link
Member

The shebang for poetrylooks like this:

#!/usr/bin/env python

Which means, poetry itself will run with any python to which python points at the time of running. Doing this makes a smooth integration of pyenv possible. Your project needs python3.6? pyenv shell 3.7.5 followed by a poetry init -n and poetry install and you are done. You need a python2? pyenv shell 2.7.15 followed by a poetry init -n and poetry install and you are done. Having a #!/usr/bin/env python3 would prevent to switch to python2 this way.

Furthermore having #!/usr/bin/env python indicates that poetry don't care with which version of poetry it runs exactly. At the moment it supports python2 and 3. The only real disadvantage about it is on the developer site ;)

With the next feature release we will drop python2 support. And I'm pretty sure we will then hardcode the shebang to python3. Until then the installer is smart enough to detect if you have a python or not. If you have one, it writes this to the shebang as it asumes, that's the python you prefer. If there is no python it will try python3 first and then python2

@pedrorrivero : Please be so kind to open a different issue for this and describe what happens.

fin swimmer

@ericriff
Copy link

When you say installer, are you taking abut get-poetry.py? Because last time I checked the shebang ended up being plain python regardless if I called get-poetry with python or python3.

@brechtm
Copy link

brechtm commented Oct 23, 2020

I would also expect that if running get-poetry.py with python3, python3 would be used for the shebang line. Even when I explicitly use python3 to install Poetry, I still get bothered by a big warning that Python 2 support is about to be dropped.

Sure, it's easy enough to adjust the shebang line manually, but not when installing Poetry in an automated way.

@brechtm
Copy link

brechtm commented Oct 23, 2020

How about simply changing the following line in get-poetry.py

allowed_executables = ["python", "python3"]

to

allowed_executables = ["python3", "python"]

This first tries Python 3, which doesn't spit out a big warning message. In fact, this is how it is done for Windows:

allowed_executables += ["py.exe -3", "py.exe -2"]

@dbersan
Copy link

dbersan commented Jun 5, 2023

The shebang for poetrylooks like this:

#!/usr/bin/env python

Which means, poetry itself will run with any python to which python points at the time of running. Doing this makes a smooth integration of pyenv possible. Your project needs python3.6? pyenv shell 3.7.5 followed by a poetry init -n and poetry install and you are done. You need a python2? pyenv shell 2.7.15 followed by a poetry init -n and poetry install and you are done. Having a #!/usr/bin/env python3 would prevent to switch to python2 this way.

Furthermore having #!/usr/bin/env python indicates that poetry don't care with which version of poetry it runs exactly. At the moment it supports python2 and 3. The only real disadvantage about it is on the developer site ;)

With the next feature release we will drop python2 support. And I'm pretty sure we will then hardcode the shebang to python3. Until then the installer is smart enough to detect if you have a python or not. If you have one, it writes this to the shebang as it asumes, that's the python you prefer. If there is no python it will try python3 first and then python2

@pedrorrivero : Please be so kind to open a different issue for this and describe what happens.

fin swimmer

could you explain where (ie. in which file) do you edit this line #!/usr/bin/env python

@vyrwu
Copy link

vyrwu commented Jun 14, 2023

In my case, I was constantly getting after a fresh poetry install on MacOSX Monterey:

❯ poetry add psycopg2

Command ['python', '-I', '-W', 'ignore', '-'] errored with the following return code 2

Error output:
Unknown option: -I
usage: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.


Input:
import sys

if hasattr(sys, "real_prefix"):
    print(sys.real_prefix)
elif hasattr(sys, "base_prefix"):
    print(sys.base_prefix)
else:
    print(sys.prefix)

What solved it for me was removing the virtual environment - it seems it's not getting deleted during poetry uninstall.

rm -rf ~/Library/Caches/pypoetry/virtualenvs

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

8 participants