poetry shell does not activate virtualenv
See original GitHub issue- I am on the latest Poetry version.
- I have searched the issues of this repo and believe that this is not a duplicate.
- OS version and name: Mac OS X, High Sierra
- Poetry version: 0.12.5
Issue
Similar to pipenv shell
, I would have expected that when running poetry shell
the virtualenv gets activated, but apparently this is not the case…
➜ which python
/Users/timon/.pyenv/shims/python
➜ poetry shell
Spawning shell within /Users/timon/Library/Caches/pypoetry/virtualenvs/YOLO-SAR-py3.7
➜ which python
/Users/timon/.pyenv/shims/python
➜ source /Users/timon/Library/Caches/pypoetry/virtualenvs/yolo-sar-py3.7/bin/activate
➜ which python
/Users/timon/Library/Caches/pypoetry/virtualenvs/yolo-sar-py3.7/bin/python
for comparison
➜ poetry run which python
/Users/timon/Library/Caches/pypoetry/virtualenvs/yolo-sar-py3.7/bin/python
Am I misunderstanding something and this is expected behaviour or is it a bug?
Thanks a lot already for your time 😃
Issue Analytics
- State:
- Created 5 years ago
- Reactions:74
- Comments:40 (5 by maintainers)
Top Results From Across the Web
poetry Virtual environment already activated - python
A workaround for this specific issue is to activate the shell manually. It might be worth aliasing the following source $(poetry env info ......
Read more >Python Poetry: Package and venv Management Made Easy
Activating the virtual environment. You can use the poetry shell command if you want to use the virtual environment interactively. This command ...
Read more >Configuration | Documentation | Poetry - Python dependency ...
Create the virtualenv inside the project's root directory. If not set explicitly, poetry by default will create virtual environment under {cache-dir}/ ...
Read more >Can I activate a Python virtual environment(poetry) from GUI ...
What I usually do is, activate the virtual environment, then just run the gui using command inside shell (which the virtual env activated)....
Read more >Working with virtualenv - PDM
Instead of spawning a subshell like what pipenv and poetry do, pdm-venv doesn't create the shell for you but print the activate command...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just in case someone else came googling for a quick but reliable temporary alternative that works in all shells:
tl; dr — Move your
pyenv
andpoetry
configuration settings to~/.bash_profile
(make surepoetry
configs come afterpyenv
’s) and out of~/.bashrc
if you’re usingbash
.I got stuck on this issue in
bash
and the main issues seem to stem from the interaction ofpyenv
andpoetry
’sPATH
-setting configuration found in my dotfiles:I found that moving these scripts to
~/.bash_profile
(as opposed to~/.bashrc
) helps resolve this issue. The problem in bash stems from the fact that~/.bash_profile
gets executed only on login (OS X registers new windows / panes as logins), whereas~/.bashrc
gets executed each time a shell is started. Becausepoetry shell
is running abash
shell under the hood, it will also source~/.bashrc
(and therefore thepyenv
script) when it is run, thus prependingpyenv
’s shims toPATH
after the virtual env is activated. By moving these configuration settings to~/.bash_profile
, we avoid this issue and the virtual env can prepend its path toPATH
unfettered.