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

How do I tell poetry to use python 2.7? #35

Closed
radix opened this issue Apr 4, 2018 · 11 comments
Closed

How do I tell poetry to use python 2.7? #35

radix opened this issue Apr 4, 2018 · 11 comments

Comments

@radix
Copy link
Contributor

radix commented Apr 4, 2018

The README indicates that poetry supports older versions of python, but when I run poetry install in a fresh project directory it's using python 3 (the same one that poetry itself is running on). I can't find an option to specify the python version to use. I specified python 2.7 as a dependency in my pyproject.toml.

@sdispater
Copy link
Member

Thanks for your interest in poetry!

You might want to take a look at https://poetry.eustace.io/docs/basic-usage/#poetry-and-virtualenvs

Basically, if you want to use a Python 2.7 virtualenv you will have to create it yourself using pew, virtualenv or even pyenv.

This is due to the fact that poetry, being a Python 3 only library, uses the venv module to create virtualenvs which will use the Python version for which poetry has been installed.

So you will be able to manage your Python 2.7 project with poetry but it won't be able to automatically create the virtualenv.

@radix
Copy link
Contributor Author

radix commented Apr 4, 2018

@sdispater Does that mean I need to activate my virtualenv manually when I want to use poetry? I really want to avoid that. What if I create the virtualenv at ~/.cache/pypoetry/virtualenvs/{project}-3.6? Will that trick poetry into using my 2.7 virtualenv?

Could poetry instead use command line tools to create the virtualenv, so it could natively support managing python 2 virtualenvs, if specifying something like --python2 on the command line when setting up a virtualenv?

@radix
Copy link
Contributor Author

radix commented Apr 4, 2018

(or adding a setting to pyproject.toml perhaps)

@sdispater
Copy link
Member

I agree this is not ideal. But, for now anyway, there is no way around it.

However, I strongly suggest to use pyenv to create your virtualenv for Python 2.7 since you can then make it activate a virtualenv automatically when you are in your project's directory. This will remove the pain of activating it manually while still being able to use poetry.

I will keep that in mind, and if I can come up with a satisfying solution to this problem I will integarte it into poetry.

@radix
Copy link
Contributor Author

radix commented Apr 5, 2018

@sdispater Could poetry shell out to CLI tools running different versions of Python instead of using the venv package directly in-process? This seems like a pretty standard way to do it that other tools use (like mkvirtualenv).

btw, it seems that creating a python2.7-based virtualenv at ~/.cache/pypoetry/virtualenvs/project-py3.6 works fine; poetry seems to be using the python version from that virtualenv so everything is natively python2.7 inside. The only issue I've run into is the creation of the virtualenv.

@sdispater
Copy link
Member

@radix Why would poetry use an external dependency while there is a perfectly functional module in the standard library?

I perfectly understand what you are saying, believe me, but I don't want to bloat the CLI with options like --python, --three, --two like pipenv because it is a pain to maintain and each developer has its own way of managing its Python versions.

poetry behaves a lot like bundler in Ruby in the sense that it will use whatever Python version it has been installed for (or the virtualenv one if it's activated).

That's why I am currently working on making poetry compatible with Python 2.7 (which in this case will use virtualenv management tool like virtualenv) so that if you have a Python 2.7-only project you would just have to install poetry for Python 2.7 and it would behave like expected.

@radix
Copy link
Contributor Author

radix commented Apr 5, 2018

Supporting poetry running on python 2.7 would be excellent. It would mirror how cargo works as well. Do you have any list of work that needs to be done that maybe I could help with?

Just for argument's sake, I think the answer to your first question is very clear: because it would enable more use cases. I personally never want to activate a virtualenv again in my life. It's one of the worst parts of Python development. I never even want to be at risk of mutating my virtualenv in a way that isn't tracked in a .toml or .lock file. So I want to make sure I use a tool that can take care of it entirely for me and isolate me from the environment.

However, the suggestion of having poetry actually run on python 2.7 would be a good alternative to supporting arguments like --two. So I'm happy as long as that's eventually possible :)

@sdispater
Copy link
Member

To support 2.7, there is a bunch of things to do:

  • Changing type annotations to Python 2.7-compatible ones
  • Adapting any non-compatible code (which can be quite complex)
  • Handling unicode problems that might occur

@sdispater
Copy link
Member

@radix Just to keep you posted.

The Python 2.7 support is coming along quite well. The only part remaining is the packaging/building part the rest is already supported (project creation and dependency installation).

So, expect full Python 2.7 support sometime next week :-)

@radix
Copy link
Contributor Author

radix commented Apr 16, 2018

Thanks so much for the Python 2.7 support, I've verified it works!

Copy link

github-actions bot commented Mar 3, 2024

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 Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants