-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 does not activate virtualenv #571
Comments
Came to file the same issue. My shell shows that a virtualenv is activated, but it's empty; if I manually activate the .venv (installing locally to the project directory) then it works, but I would expect |
You might be experiencing #497. |
@seansfkelley Confirmed, am experiencing #497. Good catch! |
I am also experiencing this. Related parts:
Things I have tried: if [[ -z "$VIRTUAL_ENV" ]]; then
eval "$(pyenv init -)"
fi Now, it just ignores |
The I think the best approach would be to stick with executing the virtualenv's |
Maybe something like |
Just in case someone else came googling for a quick but reliable temporary alternative that works in all shells:
|
@sdispater senpai please note it's actually pretty easy to make it work in a subshell for posix at least, there are only a few decisions to be made about windows compability and extra deps see #497 (comment) |
I don't have an activate script inside This is Poetry 0.12.10 installed via pip3 because of #721 In order to then get
|
@drcongo Are you sure that $ chmod u+x .venv/bin/activate Unsure about why the execution permissions are not being properly set at install time though. |
@jbmusso Yeah, positive it wasn't there. Not sure what the issue was now, I ended up dropping pyenv from my build so that may have been a contributing factor. |
I know it's hard to make a decision. Can you update docs to let users know this issue before it's resolved? @sdispater |
I came here to figure out what
I've been spending a lot of time debugging these two use cases, and haven't found a solution. To me, these are the most important commands, actually using the results of all the config work. |
tl; dr — Move your I got stuck on this issue in # Initialize pyenv when a new shell spawns
eval "$(pyenv init -)"
# Modify path for Python's poetry dependency management system
export PATH="$HOME/.poetry/bin:$PATH" I found that moving these scripts to |
@wfa207 more details at #198 (comment), which is linked from the (arguable duplicate of this issue) #497. |
@betafcc :
Or as a function poetry_activate () {
local _python="python${PYTHON_VERSION:-}" # you can do PYTHON_VERSION=2.7, PYTHON_VERSION=3.7 etc
local activation_script="$( dirname $( poetry run which ${_python} ) )/activate"
. "${activation_script}"
} update: 👇 #571 (comment) 👇 |
This is my vote too 😀 Oh! The following is already supported in latest source "$( poetry env info --path )/bin/activate" This is more performant (relevant if you want to do something like 'try/ensure' virtualenv activated before every invocation of [ -z "${VIRTUAL_ENV:-}" ] && source "$( poetry env info --path )/bin/activate" So then IMHO all we really need is
|
If you're on Poetry 0.12.x that doesn't have source "$(poetry debug:info | rg '.*Path:[^/]+(.*)' -r '$1')/bin/activate" (rg = ripgrep, though you could do it with grep and sed too) or in alias form with escaping alias activate=$'source "$(poetry debug:info | rg \'.*Path:[^/]+(.*)\' -r \'$1\')/bin/activate"' |
Just a heads up for this to work make sure you've enabled the creation of virtualenvs: poetry config settings.virtualenvs.create true |
For those on a Poetry version without the [ -z "${POETRY_ACTIVE}" ] || source "$(poetry debug:info | grep Path | awk '{print $3}')/bin/activate" |
@ziofil For fish, try: |
For those of you in a Windows shop, the following works in Powershell. I have something similar in my GitLab CI configuration to take advantage of the venv caching of poetry, among other beautiful things that poetry does invoke-expression $($(poetry debug:info | sls Path | Out-String -Width 1000 | % {$_.replace("* Path: ", "").trim()}) + "\Scripts\activate.ps1") |
Just for info, while waiting for a proper fix, I'm using the following alias:
Advantage is that, just like |
Pytest is not found, so I don't think the virtualenv created by poetry has been activated. I found a hacky solution I'm trying to this here: python-poetry/poetry#571 (comment)
FTR:
The activate script must be sourced, not run, in order to edit the current shell configuration rather than run a sub-shell. That’s why it does not have the executable bit. (If Python install layouts had standard data directories like Editing the current shell has issues and proves confusing, so there are other approaches based on sub-shells exist, like inve or poetry shell. |
In my case |
This was still broken in 1.0.0b7, but has been resolved in 1.0.0b8 (and is still working in 1.0.0b9). Thank you. |
The |
I am experiencing this issue in Poetry version 1.0.2; I use the setting that puts the venv in the local directory. The venv was created with I have some pyenv environment variable stuff in my Note I also have miniconda installed, though I don't use it much. I tried moving these two lines to before poetry's stuff in
But now if I run
|
Am just looking for a way to deactivate the env poetry created. even when i close the poetry shell and run poetry env list it still show (Activated) how can i deactivate this? or is it ok to just leave it activated? |
@sdispater I am experiencing this still on poetry 1.0.5 running on Ubuntu 20.04 under WSL2. the virtual environment is in ~/.cache/pypoetry/virtualenvs |
Whoever ends up here might be interested in setting up automatic Poetry virtualenv activation using direnv. |
I've experienced this with Poetry 1.1.7, in Fedora34 under WSL2 I tracked it down these lines in
If the child shell executes those lines (as per default in Fedora34 Remix for WSL ), then, after I'm not sure where lies the problem, but it does not seem to be related to the PATH only (as #497 seems to suggest), it's the whole environment . My fix was to modify that script so it does NOT run on child shells. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue
Similar to
pipenv shell
, I would have expected that when runningpoetry shell
the virtualenv gets activated, but apparently this is not the case...for comparison
Am I misunderstanding something and this is expected behaviour or is it a bug?
Thanks a lot already for your time :)
The text was updated successfully, but these errors were encountered: