poetry icon indicating copy to clipboard operation
poetry copied to clipboard

`poetry shell` and `poetry run` are not activating the virtual environment

Open quant5 opened this issue 1 year ago • 2 comments

  • Poetry version: 1.7.1
  • Python version: 3.11.5 (Anaconda distribution)
  • OS version and name: Windows 11
  • pyproject.toml: N/A
  • [x] I am on the latest stable Poetry version, installed using a recommended method.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] I have consulted the FAQ and blog for any relevant entries or release notes.
  • [x] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

Issue 1 poetry shell is not activating the virtual environment correctly. I added a poetry-demo project using poetry new poetry-demo, went into the folder, and ran poetry install. But for some reason poetry shell claims to spawn the shell but actually doesn't.

~\Development\poetry-demo is pkg v0.1.0 via py v3.11.5 on aws (us-east-1)
> poetry shell -vvv
Using virtualenv: C:\Users\kevin\AppData\Local\pypoetry\Cache\virtualenvs\poetry-demo-gcIWnW3E-py3.11
Spawning shell within C:\Users\kevin\AppData\Local\pypoetry\Cache\virtualenvs\poetry-demo-gcIWnW3E-py3.11

~\Development\poetry-demo is pkg v0.1.0 via py v3.11.5 on aws (us-east-1)

Expected behavior - this is using the source $(poetry env info --path)/Scripts/activate script, which successfully activates the environment.

~\Development\poetry-demo is pkg v0.1.0 via py v3.11.5 on aws (us-east-1)
> source $(poetry env info --path)/Scripts/activate

~\Development\poetry-demo is pkg v0.1.0 via py v3.11.5 (poetry-demo-py3.11) on aws (us-east-1)
>

Issue 2 relatedly, poetry run python is not running python. The command simply runs nothing.

> poetry run python

# nada...

But the python is there, and pointing to it directly works correctly:

> /c/Users/kevin/AppData/Local/pypoetry/Cache/virtualenvs/poetry-demo-gcIWnW3E-py3.11/Scripts/python.exe
Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Additional details

  • I did a fresh install of poetry 1.7.1.
  • I checked that poetry is installed correctly:
> which poetry
/c/Users/kevin/AppData/Roaming/Python/Scripts/poetry
  • Outside of poetry, python is working as expected:
> python
Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
  • Poetry env info is showing the correct executable
> poetry env info

Virtualenv
Python:         3.11.5
Implementation: CPython
Path:           C:\Users\kevin\AppData\Local\pypoetry\Cache\virtualenvs\poetry-demo-gcIWnW3E-py3.11
Executable:     C:\Users\kevin\AppData\Local\pypoetry\Cache\virtualenvs\poetry-demo-gcIWnW3E-py3.11\Scripts\python.exe
Valid:          True

System
Platform:   win32
OS:         nt
Python:     3.11.5
Path:       C:\Users\kevin\anaconda3
Executable: C:\Users\kevin\anaconda3\python.exe

Any help or suggestions are appreciated. I have tried uninstalling and installing poetry multiple times (all using the official installer).

quant5 avatar Feb 16 '24 04:02 quant5

unlikely that anyone can help with something that is broken only on your machine: but do please report back if and when you figure it out, perhaps the next person will benefit

dimbleby avatar Feb 16 '24 08:02 dimbleby

fair. what is the expected behavior of poetry when one uninstalls and reinstalls python (in the same location)? This bug only started popping up when I upgraded Anaconda from 3.9 to 3.11. I did not remove poetry upon first reinstall, but removed and reinstalled it afterwards.

relatedly, are there any artifacts (env vars, directories and the like) left behind after an uninstall of poetry that may cause the issue?

quant5 avatar Feb 16 '24 13:02 quant5