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 shell unexpected behavior - spawning the "wrong" shell #6721

Open
4 tasks done
drorata opened this issue Oct 6, 2022 · 3 comments
Open
4 tasks done

poetry shell unexpected behavior - spawning the "wrong" shell #6721

drorata opened this issue Oct 6, 2022 · 3 comments
Labels
area/shell Related to `poetry shell` area/windows For Windows-specific issues kind/bug Something isn't working as expected

Comments

@drorata
Copy link

drorata commented Oct 6, 2022

  • Poetry version: Poetry (version 1.2.1)
  • Python version:
Poetry
Version: 1.2.1
Python:  3.10.5

Virtualenv
Python:         3.10.5
Implementation: CPython
Path:           C:\Users\my_user\AppData\Local\pypoetry\Cache\virtualenvs\pyspark-write-demo-CwtTbJGc-py3.10
Executable:     C:\Users\my_user\AppData\Local\pypoetry\Cache\virtualenvs\pyspark-write-demo-CwtTbJGc-py3.10\Scripts\python.exe
Valid:          True

System
Platform:   win32
OS:         nt
Python:     3.10.5
Path:       C:\Users\my_user\.pyenv\pyenv-win\versions\3.10.5
Executable: C:\Users\my_user\.pyenv\pyenv-win\versions\3.10.5\python.exe
  • I am on the latest stable Poetry version, installed using a recommended method. *I believe that I installed it using pip and that could be the reason of my issue. However, due to certificates issue and Co, I was not able to install poetry using (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

When trying to activate the created environment using poetry -vvv shell I get:

Loading configuration file C:\Users\my_user\AppData\Roaming\pypoetry\config.toml
Loading configuration file C:\Users\my_user\AppData\Roaming\pypoetry\auth.toml
Using virtualenv: C:\Users\my_user\AppData\Local\pypoetry\Cache\virtualenvs\pyspark-write-demo-CwtTbJGc-py3.10
Spawning shell within C:\Users\my_user\AppData\Local\pypoetry\Cache\virtualenvs\pyspark-write-demo-CwtTbJGc-py3.10

C:\Users\my_user\dev\pyspark_write_demo>

The problem is that I get a new type of shell which is not working as I expect. Consider the following screen shot:

image

As you can see, the new prompt is different than the one where I execute poetry shell. In turn, the new shell doesn't have many configurations that I'd have in the original shell (e.g. the nice-looking prompt).

However, if I try to start the environment "directly":

 C:/Users/my_user/AppData/Local/pypoetry/Cache/virtualenvs/pyspark-write-demo-Rmcv68Jg-py3.10/Scripts/Activate.ps1

I get the expected behavior as can be seen in the following image:

image

Why is this happening? What have I configured wrongly with Poetry?

@drorata drorata added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Oct 6, 2022
@bmarroquin
Copy link
Contributor

This would happen to me too when using pyenv on windows. I think it is due to pyenv creating shims using .bat files which results with shell detection returning cmd.exe instead of powershell.exe. Try creating an environment without pyenv and see if that helps. You might also have to re-install poetry without going through pyenv shims.

A quick way to test this would be to use shellingham to detect the shell using both python.bat and C:\Users\my_user\.pyenv\pyenv-win\versions\3.10.5\python.exe. If python.bat returns cmd.exe and python.exe does not, then pyenv is the issue.

@ekralc ekralc added area/windows For Windows-specific issues area/shell Related to `poetry shell` and removed status/triage This issue needs to be triaged labels Oct 7, 2022
@drorata
Copy link
Author

drorata commented Oct 10, 2022

Thanks @bmarroquin for the hints. It seems like this is the right direction. Although I'm not yet sure... Here's what I did: firstly, I added shellingham to my environment (using poetry add shellingham). Next, I activated the environment twice, once "manually" using a manual call to Activate.ps1. In this case the output of detect_shell() is: ('powershell', 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'). Secondly, I activated the environment using poetry shell and in this case the output of detect_shell() is: ('cmd', 'C:\\Windows\\System32\\cmd.exe').

So, I guess you're pointing at the right direction. Unfortunately, I don't know how to proceed. How can I create an environment without pyenv? What version of Python will be used? How can I control which version of Python will be used in an environment?

@bmarroquin
Copy link
Contributor

bmarroquin commented Oct 10, 2022

Poetry will default to the system python (first one in path) when creating environments. If you want to pick a specific python version, you can use poetry env use <interpreter>. You can read more about that in the poetry env documentation. Currently there is a limitation on windows where you can't specify the specific version but using the full path should work. I am working on that change here #5778.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/shell Related to `poetry shell` area/windows For Windows-specific issues kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

3 participants