-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
No method to control the python version used #522
Comments
And specify the "current python" when running impacted commands e.g. Having a way to e.g. |
There are ways to do experimentation in tox but they are a bit confusing and hacky if your problem is user reported and not a tox test failure. Yeah, it seems like it'd make sense to be able to control this on the command line. Another perspective on this is Rust's |
This is no longer true (I forgot to update this part of the documentation). As of version Basically, you want to use a tool like Making Poetry a Python versions manager is not a direction I want to go in since there are tools that do it already. |
Nice! Looks like that solves the underlying requests which is fine than its different than the suggestion. So it seems that this is now just down to documentation updates? |
Drat, doesn't look like pyenv supports Windows. |
I haven't used it but maybe https://docs.python.org/3/using/windows.html#python-launcher-for-windows can help here. |
I'm experiencing issues here as well when trying to bootstrap a project that requires a different version of python than that which I used to install poetry.
Another approach would be to let the user create the virtualenv themselves. I know this is supported via the |
That's why you should now use the recommended installer which will make Poetry pick up the currently activated Python version. That makes it particularly handy when coupled with
That's planned actually since that's something that has bitten users before.
I have said it before but I have no plan to make Poetry a Python version manager.
Just so you know, I plan on adding support for per-project settings via the |
Yes, this change just bit me on my build servers (Ubuntu 18.04) where I have always installed Are you saying that going forward that absolutely will not work and I will need to bootstrap |
@jaswilli Not necessarily. If your default |
@sdispater I 100% agree about avoiding integrating any sort of pyenv support into poetry. The
Poetry is shipped on PyPI and as such supports being installed into a virtualenv. It's an official installation method. Decoupling poetry from the version of python it's running on should really be supported. I don't have a habit of switching the default python in my shell and I consider it a bad practice. My "python" command in my shell always points at the system python. This is why things like |
These steps work for me.
I want an environment with python 3.7.0 # List all available python versions
pyenv install -l
# Install release
pyenv install 3.7.0
# Create working directory
mkdir myapp-project
cd myapp-project
pyenv virtualenvs
pyenv local 3.7.0
# Now we create a virtual env based on the version of python specified above.
# The following will also install all of the default packages as specified in ~/.pyenv/default-packages
# These default packages may be used to install useful commands inside of the project, such as black for example.
pyenv virtualenv myapp
pyenv local myapp
poetry new --src myapp
cd myapp
echo 'Python in virtual environment should be: '$HOME'/.pyenv/versions/myapp/bin'
sed -i 's/^python\ =\ \".*/python\ =\ \"3.7.0\"/' pyproject.toml
poetry install As I type this out it occurs to me that I could most probably just add |
I'm just evaluating poetry today and for my normal usecases being able to easily work with a couple of Python versions without shuffling some global state around is absolutely crucial. I often worked with people who aren't experts on Python and its wacky (even though it performs very well, in my opinion) way of isolating dependencies and runtime versions with virtualenvs. So I had to explain that, and debug and set it up on people's machines, and on CI servers. But it was doable. Pyenv would complicate that, I'm affraid. On Ubuntu machines we'd just install whatever Pythons we need from deadsnakes, on Macs that'd be something from Homebrew. With Docker images we just pick the version of And we could maintain some legacy projects in 2.7, stable stuff in 3.6, and evaluating 3.7. @sdispater If what I'm talking about is outside of the scope of this project, then maybe we can create some disclaimer in the docs saying what workflows this project isn't for? Cause for me "Python dependency management and packaging made easy" is a bit of a false advertising right now :) But I'll be sad if I can't use poetry in the future, cause it seems way well thought through and performant than Pipenv, which I use right now in a few projects, while disliking its confusing and non-standard CLI. |
How so? The tagline does not mention Python versions management so I don't see how it is false advertising.
It's explicitly stated in the documentation how Poetry should be used: https://poetry.eustace.io/docs/#installation or https://poetry.eustace.io/docs/basic-usage/#poetry-and-virtualenvs
I don't see how Poetry prevents you from doing that. You can use tox with Poetry see an example here: https://github.com/sdispater/tomlkit/blob/master/tox.ini Now, I will say it again: Poetry is not and will never be a Python versions manager. It may be that Pipenv does it and people are now used to it but this is not the role of a package/dependency manager. And this choice has precedence since that's what a lot of package managers do in other languages: |
@sdispater I think you misunderstood me and I misunderstood the relation of Sorry about the confusion, but I was confused as well :) |
@butla Poetry does create virtualenvs to install the packages needed for the project in order to work isolated. The difference with PIpenv is that Poetry will pick up the currently activated Python version to create or use the virtualenvs. |
@sdispater Well, yeah, but that it'll only create a virtualenv for the Python versions it's installed with, or the one set by pyenv, which is weird for me. Switching my user python with pyenv all the time seems like not as nice of a user experience. But I've noticed a lot of Mac people using pyenv, so that might be an OS culture difference? I don't know. For me and a lot of other devs I know it's natural to have multiple versions system-wide as Anyway, since were on managing virtualenvs - with virtualenv or virtualenvwrapper I can specify the python version I want as a parameter. Here I don't see that option. If I do
And I know that this might be totally coherent with the way this project is supposed to be used, but it's just surprising for me, and probably other people with habits similar to mine. |
This workflow basically means I need to install poetry into every virtualenv I use and create the virtualenvs myself and activate the virtualenvs myself. This is objectively worse than pipenv which creates the virtualenv for me using the python interpreter that I tell it to use. Note again, this has nothing to do with pyenv or any other python version management being integrated into poetry. I just want the ability to tell poetry which python to use explicitly when it creates the virtualenv instead of being coupled to the version of python running poetry. Right now I have two options:
Proposed workflow:
|
@mmerickel You have no reason to install poetry into every virtualenv. The global installation will detect and work with whatever virtualenv you have activated. So it's
but without installing poetry into the virtualenv, just using the global one. So it's not as dramatic as you describe it. |
@epage On windows you can change poetry.bat to execute the launcher (replace "python" by "py") and use an environment variable to specify which of the installed Python versions should be used:
...will create a Python 3.7 virtual env. It would be nice if the launcher could be configured via a py.ini file in the project directory. This is not possible at the moment but it would not be difficult to write a Python 2/3 compatible script to look for such a py.ini-file. In poetry.bat this py.ini-finder should then be run as first step with whichever python version is executed before the launcher is used to run poetry with the python version specified in py.ini. |
I have multiple versions of python installed and activated on my machine (a mac using pyenv). This breaks poetry: $ pyenv versions
system
* 2.7.15 (set by /Users/mike/.pyenv/version)
* 3.7.1 (set by /Users/mike/.pyenv/version)
$ python -V
Python 2.7.15
$ python3 -V
Python 3.7.1
$ cat pyproject.toml
[tool.poetry]
name = "stuff"
version = "0.1.0"
description = "stuff"
authors = ["Mike Lane <me@redacted.com>"]
license = "MIT"
[tool.poetry.dependencies]
python = "^3.6"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
$ poetry add django
[RuntimeError]
The current Python version (2.7.15) is not supported by the project (^3.6)
Please activate a compatible Python version.
add [-D|--dev] [--git GIT] [--path PATH] [-E|--extras EXTRAS] [--optional] [--python PYTHON] [--platform PLATFORM] [--allow-prereleases] [--dry-run] [--] <name> (<name>)... Would be nice if I could at least specify which python to use for poetry somehow. |
If you run poetry in a virtualenv with your desired python, it should work. (Not saying that's the way it ought to be, but it should work anyway.) |
For those who don't want to go an edit the shebang in function ensure_python3 {
# Check if `python` evalutes to Python 2 or Python 3
if [[ "$($(which python) -c 'import sys; print(sys.version_info[:][0])')" -lt 3 ]]; then
# Check if there is a venv in the working directory with a Python 3 environment installed
if [[ ! -z "$(find . -wholename "*/bin/python3")" ]]; then
local python3_venv_bin_dir="$(dirname "$(find . -wholename "*/bin/python3")")"
source "${python3_venv_bin_dir}/activate"
else
printf "\nPlease activate a Python 3 virtual environment and then rerun\n\nbash scripts/install_env.sh\n\n"
exit 1
fi
fi
return 0
} This isn't helpful for people who want to have their day to day activities be uninterrupted, but you're probably already in virtual environments most of the time anyway(?) so that hopefully isn't too big of a deal. If you don't want to use |
Like many others, I have found the the current situation with Python versions confusing, and hope to clarify or pin some things down here. Many operating systems (e.g. Ubuntu) support multiple Python versions simply by having official versions with different names, e.g. These systems have multiple Python installations. So using a phrase in the Poetry documentation like use the current Python installation is ambiguous. It would at the very least be helpful to clarify that the new behavior of version 0.12.x is to always search There can even be system tools (or project scripts) that assume that For these sorts of reasons, most other Python tools provide methods to control which version of Python they are used with. It doesn't seem complicated, and they don't portray that as becoming "Python version managers". They just allow command-line arguments or configuration settings to specify the name of the executable to use for Python. So like many others, I hope to see that supported in Poetry. And it sounds like previous versions did essentially have an easy way to get a Poetry installation that that worked by default with In the meantime, it would be helpful to build on the post by @matthewfeickert to explore approaches that result in the smallest impact to users while providing the flexibility we seek. These seem like possible options, and I'd like to know which might work reliably:
|
This seems like the most user friendly option, but requires the most work from whoever is going to write the PR. Also, as 2020 and the end of Python 2.7 support looms it might be worth considering if making the shell alias I realize that's not a very substantive comment, but just my thoughts. |
To jump in on this, @sdispater you're very often using the phrase For example on my machine (where I use pythonz) I have:
/edit:
From that point forwards everything in that venv / project (the two concepts are kind of linked in my use) will be on Py3.7 without having to modify 'global' state. |
From the user perspective, this is a big problem. It is for me too. Typically, At the same time, different projects require different Python versions. I feel there's a conceptual clash here — Other tools a) are happy to use one of the system Python binaries (-m venv; virtualen; pipenv), read the version from the project spec and find python in $PATH (tox, pipenv), as well as allow to specify highly-specific Python build (-m venv, pipenv --python=, pyenv virtualenv). In the ideal world, I'd use In the practical wold, some projects are stuck on 3.6; some unlucky dev may run across a project written for python 2.x and it will be their job to update the project to work on 3.x, which is often an incremental process, during which the developer might even alternate between 2.x and 3.x branches in the repository. |
This is a bit of a hack but if you are on Ubuntu, are not using pyenv and want projects created with poetry to use python3 then you can use the following command when installing poetry.
I'm not a pyenv expert but pyenv does create a shim for python3 so you should still be able to use pyenv to select python version. Don't use the above command if you are planning on using python2. |
FYI: As a stopgap I'm for now using this shell function (ZSH specific, sorry) to wrap poetry and this basically solves 95% of the problem for me. |
FWIW, I don't like pyenv at all. It doesn't seem to provide enough benefit to justify how much it interferes with my workflow. (This may be because I have a long history of coping with lots of different python versions that I had to compile myself and then manage in lots of different virtualenvs because pyenv hadn't been written yet.) I'm obviously in the group with lots of different python versions available on my PATH. And I'm using virtualenvwrapper. Be that as it may, I've had very good luck using To me that seems less burdensome than pyenv (maybe I just need to give it more of a chance). |
pyenv is not a solution for
A |
Looks like we'll get what we need when 1.0 releases: #731 has already been merged in and provides |
FWIW, I seem to be having a similar situation which I find confusing. Hopefully this is clear:
My selected version is My larger concern is that |
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. |
-vvv
option).Issue
I found it confusing when my
pyproject.toml
file sayspython = "3"
and yet a Python 2.7 venv was being created.I then noticed
I assumed it was using the version of python I ran
get-poetry
with. I tried again withpython3
and still no luck.It seems its just hard coded in
poetry.bat
aspython
and for me to change, I need to change that file.To me, the ideal thing would be to a way to get arbitrary versions of python, like tox, and allow it to be configured on a per-project basis (like as a dev-dependency).
Workround
Edit
poetry.bat
to change what python gets invoked.The text was updated successfully, but these errors were encountered: