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 not using the correct python version #7075

Closed
shanewazabbas opened this issue Nov 22, 2022 · 24 comments
Closed

Poetry not using the correct python version #7075

shanewazabbas opened this issue Nov 22, 2022 · 24 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged status/waiting-on-response Waiting on response from author

Comments

@shanewazabbas
Copy link

shanewazabbas commented Nov 22, 2022

> poetry shell
The currently activated Python version 3.9.14 is not supported by the project (>=3.10.1,<3.11).
Trying to find and use a compatible version. 
Using python3 (3.10.7)
Skipping virtualenv creation, as specified in config file.
Spawning shell within /Users/shaneabbas/.pyenv/versions/3.9.14

It says using 3.10.7 but the last line says otherwise.
If I do poetry install, it chooses to still use 3.9.14

Keep in mind that I'm using pyenv and local .python-version file

> python --version
Python 3.10.7
> cat .python-version 
3.10.7
> poetry env info

Virtualenv
Python:         3.9.14
Implementation: CPython
Path:           NA
Executable:     NA

System
Platform:   darwin
OS:         posix
Python:     3.9.14
Path:       /Users/shaneabbas/.pyenv/versions/3.9.14
Executable: /Users/shaneabbas/.pyenv/versions/3.9.14/bin/python3.9

There is nothing crazy going on here on my end. How are we not able to handle just having the current python version be respected for poetry? I'm on a mac

@shanewazabbas shanewazabbas added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Nov 22, 2022
@shanewazabbas
Copy link
Author

Also this doesn't work:

> poetry env use $(pyenv which python3.10) -vvv
Loading configuration file /Users/shaneabbas/Library/Preferences/pypoetry/config.toml
Loading configuration file /Users/XXX/poetry.toml
Skipping virtualenv creation, as specified in config file.
Using virtualenv: /Users/shaneabbas/.pyenv/versions/3.9.14

This is rather frustrating...

@clintonroy
Copy link
Contributor

I really don't understand what pyenv is, I've never used it, and thus I'm not well placed to try to help here.

Buuuut, if poetry isn't making the virtual environment, that means the user is, and that means it's on you?

@shanewazabbas
Copy link
Author

I really don't understand what pyenv is

Then look it up...
There's even documentation about pyenv from poetry: https://python-poetry.org/docs/managing-environments/#switching-between-environments

@finswimmer
Copy link
Member

If you expect that Poetry picks up the current activated Python version, you have to set virtualenvs.prefer-active-python to true (https://python-poetry.org/docs/configuration/#virtualenvsprefer-active-python-experimental)

@shanewazabbas
Copy link
Author

I have and it still doesn't work...

@shanewazabbas
Copy link
Author

Even then the original output I posted is clearly a bug. It shouldn't be saying it's using python3 (3.10.7) when it actually isn't.

> poetry shell
The currently activated Python version 3.9.14 is not supported by the project (>=3.10.1,<3.11).
Trying to find and use a compatible version. 
Using python3 (3.10.7)
Skipping virtualenv creation, as specified in config file.
Spawning shell within /Users/shaneabbas/.pyenv/versions/3.9.14

Not to mention that message also contradicts poetry env info as well.

@dimbleby
Copy link
Contributor

bugs notwithstanding, I wonder what you are trying to achieve here? You say you have configured poetry to prefer the active python, we can see you have configured poetry not to create a virtual environment - what are you hoping that poetry env or poetry shell will do?

If you want the python that's active and not a new virtual environment... just do nothing?

@shanewazabbas
Copy link
Author

If you want the python that's active and not a new virtual environment... just do nothing?

You understand that poetry install doesn't just magically work right? It has to install the packages somewhere? Where do you think it will do that?

If it installs the packages in python3.9 and I'm using python 3.10, how do you suppose this will work?

@dimbleby
Copy link
Contributor

where do you think it will do that? You have configured poetry not to create a virtual environment

Skipping virtualenv creation, as specified in config file.

Again: what are you expecting to happen?

@shanewazabbas
Copy link
Author

Reread everything I posted. I cannot make it any more clear...

@shanewazabbas
Copy link
Author

You have configured poetry not to create a virtual environment

Yes, because I'm providing the environment.
Might as well remove anything to do with pyenv in the documentation.

@finswimmer
Copy link
Member

Hey @shanewazabbas,

for further debugging please provide the output of poetry config --list.

From what I can see until now:

"The currently activated Python version 3.9.14 is not supported by the project (>=3.10.1,<3.11)." indicated that you haven't set virtualenvs.prefer-active-python to true.

"Skipping virtualenv creation, as specified in config file." means you have set virtualenvs.create to false. This disable venv creation by poetry at all. Also a poetry env use will not create a venv for you.

A wrong output of poetry env info is possible to due a bug, which is fixed in master by #6986

fin swimmer

@castagninojose

This comment was marked as off-topic.

@finswimmer

This comment was marked as off-topic.

@matthewhughes934

This comment was marked as off-topic.

@finswimmer finswimmer added the status/waiting-on-response Waiting on response from author label Nov 27, 2022
@doolio
Copy link
Contributor

doolio commented Dec 6, 2022

@shanewazabbas I believe we are suffering the same or similar issue. See discussion #6978.

@garrettargenna
Copy link

I’m having a similar issue where I have a terminal opened in a directory that contains a pyproject.toml with python pinned to python 3.10.8 and a .python-version file also set to 3.10.8. If I run
‘python —version’
I get 3.10.8.
But if I run
‘poetry env info’
It lists the system version at 3.10.10 which is the pyenv global version I used when installing poetry.. fine everything should still work because I have ‘virtualenvs.prefer-active-python’ set to true.
But when I run
‘poetry update’
I get the following error:
"The currently activated Python version 3.10.10 is not supported by the project (3.10.8).
Trying to find and use a compatible version."

@dnabb
Copy link

dnabb commented Mar 19, 2023

Similar issue (using pyenv-win) where poetry seems to ignore virtualenvs.prefer-active-python = true and tries to use system python instead:

From a new shell in the project directory:

pyenv which python
C:\Users\mysuer.pyenv\pyenv-win\versions\3.9.13\python.exe

poetry --version
Poetry (version 1.4.0)

poetry config --list

...only showing the virtualenvs settings
virtualenvs.create = true
virtualenvs.in-project = false
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}\\virtualenvs"
virtualenvs.prefer-active-python = true
virtualenvs.prompt = "{project_name}-py{python_version}
...

Now, let's try to acivate another python version:

pyenv shell 3.10.6
pyenv which python
C:\Users\myuser.pyenv\pyenv-win\versions\3.10.6\python.exe

Looking good. Now, let's start poetry:

poetry shell
*The currently activated Python version 3.9.13 is not supported by the project (^3.10.6).
Trying to find and use a compatible version.

[WinError 2] The system cannot find the file specified*

@pelayogmp
Copy link

Same problem here, using poetry 1.4.1 on windows

Global python version is 3.11.2 used to install poetry:

λ pyenv global
3.11.2
λ python --version
Python 3.11.2

Test project requires python 3.10.10, and poetry install fails:

 cd $HOME/git/test_project
λ pyenv local
3.10.10
λ python --version
Python 3.10.10
λ poetry install
The currently activated Python version 3.11.2 is not supported by the project (>=3.10,<3.11).
Trying to find and use a compatible version.

[WinError 193] %1 no es una aplicación Win32 válida

However using poetry env use <full_path_to_python_shim> worked for me:

poetry env use  %HOME%\.pyenv\pyenv-win\shims\python.bat
Creating virtualenv test-project in ...\test_project\.venv 
Using virtualenv: ...\test_project\.venv

λ poetry shell
Spawning shell within ...\test_project\.venv 

(test-project-py3.10) ...\tutor_nicegui>python --version
Python 3.10.10

IMHO the documentation about pyenv should be clarified.

@xyxel
Copy link

xyxel commented Apr 4, 2023

I have the same issue. Looks like the reason is commit: #7471
If add "shell=True" to subprocess.check_output of _full_python_path method, everything works fine.

@dimbleby
Copy link
Contributor

dimbleby commented Apr 4, 2023

A problem reported in November 2022 is certainly not caused by a commit made in February 2023

@xyxel
Copy link

xyxel commented Apr 5, 2023

Yes, you are right, I'm not sure about the original issue. But "shell=True" can help people who left three last messages.
On Windows pyenv uses batch files for python management. In particularly, python.bat file. If you execute subprocess with shell=False, Popen doesn't use python.bat, but use python.exe that is used for poetry execution.

Please look at example:

subprocess.call("python")
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
exit()
0
subprocess.call("python.bat")
Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
exit()
0
subprocess.call("python", shell=True)
Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Thank you.

@dimbleby
Copy link
Contributor

dimbleby commented Apr 5, 2023

well let's try to keep separate issues separate - please raise new issues for new problems.

(perhaps we want a shutil.which("python") round about

executable = EnvManager._full_python_path("python")
, feel free to experiment and open an MR)

@finswimmer
Copy link
Member

Hello @shanewazabbas,

you haven't come back to this issue for a long while. So I assume this is solved in the meantime and I can close this ticket.

Feel free to leave a comment if you disagree.

fin swimmer

@finswimmer finswimmer closed this as not planned Won't fix, can't repro, duplicate, stale Mar 11, 2024
@python-poetry python-poetry locked as resolved and limited conversation to collaborators Mar 11, 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 status/triage This issue needs to be triaged status/waiting-on-response Waiting on response from author
Projects
None yet
Development

No branches or pull requests