poetry: poetry and pyenv don't work well together
I am using pyenv to manage my python versions and virtualenvs. This seems to cause some problems with poetry.
>> which python
~/.pyenv/shims/python
>> which pip
~/.pyenv/shims/pip
>> poetry run which python
~/.cache/pypoetry/virtualenvs/XXXXX-py3.6/bin/python
>> poetry run which pip
~/.pyenv/shims/pip
This seems to cause the issue, that packages are installed in to the python version set by pyenv, but the python interpreter is used from the poetry virtualenv. This is no problem, when I activate the virtualenv first and then run poetry install
But if I want to rely on poetry’s automatic virtualenv management, this doesn’t work anymore.
If you need more info I’ll gladly provide it.
Thanks for your great work and tool, it’s a real pleasure to work with 😃
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 38
- Comments: 27 (7 by maintainers)
I am currently using
pyenv
on MacOS and I don’t have any problem making it working.I didn’t do anything special, I only have this on my
.zshrc
:Just to give my feedback here, I’m new to poetry and encountered issues when using pyenv and poetry together. Basically, it installed packages to a newly created virtualenv directory that was then nowhere to be found, poetry shell didn’t work, etc.
I installed poetry using
curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
. My python used there is python 3.7.1 from ~/.pyenv/shims/python. Then I went to my code repository, activated my pyenv virtualenv, executedpoetry install
and had the problems mentioned above.I’m just commenting here, because I believe there is some underlying issue here that’s not fixed.
Extra feedback on this issue, I’m new to both
pyenv
andpoetry
, here are the steps to reproduce my environment.Which means that I cannot use the shell to interact with poetry’s virtualenv.
poetry shell
spawns a new shell adding a new folder to PATH env variable. But new shell also loads all rc scripts like .bash_profile. That file likely has pyenv initialization lineeval "$(pyenv init -)"
that overrides venv pythonAvoiding initializing pyenv within spawned shell works for me.
But something doesn’t look good - it’s the same case as in first post in this thread:
python
points to virtualenv python, butpip
points to pyenv shim. Shouldn’tpip
point to virtualenv too?If people are still having issues with pyenv I suggest switching from pyenv to asdf. It can manage versions of not only python and for me works perfectly fine with poetry.
I use
pyenv
and I am getting inconsistent behavior betweenpoetry run
andpoetry shell
.I would not expect the
which
command to point at different paths between theshell
andrun
commands as it is here.Edit, the
.zshrc
solution above with the$(pyenv virtualenv-init -)
fixed this for me. I would say that is doing something “special” to make it work though.If you’re using pipsi to install poetry, make sure you’re using the latest version available, from the git repository, because the one on PyPI is about three years old.
pip install -U --user git+https://github.com/mitsuhiko/pipsi/
The old version always uses virtualenv, even if you’re on Python 3, and that messes the venv module up.
Deleting
.python-version
on every other base directory than project works…/Users/abc/based-dir/project-dir/
Then I deleted the
/Users/abc/.python-version
and/Users/abc/based-dir/.python-version
Just kept ``/Users/abc/based-dir/project-dir/.python-version`@tkossak I guess
pipsi
is the way to go then.I think the
PYENV_VERSION=system
approach worked for me because thesystem
python is actually the one installed withhomebrew
, which doesn’t require root privileges.edit: typos, clarifications
I’ve had this same issue. For me, it only works if I tell
pyenv
to use thesystem
python version:Installed this way, the
poetry
command is available everywhere. @tkossak does this work for you?