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

About environment mangement and .venv folder #1770

Closed
1 task done
squirrel532 opened this issue Dec 19, 2019 · 15 comments · Fixed by #2771
Closed
1 task done

About environment mangement and .venv folder #1770

squirrel532 opened this issue Dec 19, 2019 · 15 comments · Fixed by #2771
Assignees
Labels
area/venv Related to virtualenv management kind/bug Something isn't working as expected

Comments

@squirrel532
Copy link

squirrel532 commented Dec 19, 2019

  • I have searched the issues of this repo and believe that this is not a duplicate.

Issue

I found that poetry prefer using .venv folder inside as the virtual environment of project. But this behavior is not described in doc. I think it will be good to write down this.

@squirrel532 squirrel532 added the area/docs Documentation issues/improvements label Dec 19, 2019
@finswimmer
Copy link
Member

Hello @azdkj532,

this is definitly not the default behaviour. I guess you have set in in your config, either global or local, sometime before :)

fin swimmer

@etijskens
Copy link

I am surprised by the answer of fin swimmer
this is my config.

poetry config --list
cache-dir = "/Users/etijskens/Library/Caches/pypoetry"
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/etijskens/Library/Caches/pypoetry/virtualenvs
I see no reference that '.venv' is the default name...

@squirrel532
Copy link
Author

squirrel532 commented Dec 19, 2019

@finswimmer Could you have a look on this ? May it's a bug.

~/Workspace/plurkcore(master ✗) poetry env info

Virtualenv
Python:         2.7.17
Implementation: CPython
Path:           /home/larry/.cache/pypoetry/virtualenvs/plurkcore-xdkz89K8-py2.7
Valid:          True

System
Platform: linux
OS:       posix
Python:   /home/larry/.pyenv/versions/2.7.17
~/Workspace/plurkcore(master ✗) virtualenv .venv
New python executable in /home/larry/Workspace/plurkcore/.venv/bin/python2.7
Also creating executable in /home/larry/Workspace/plurkcore/.venv/bin/python
Installing setuptools, pip, wheel...
done.
~/Workspace/plurkcore(master ✗) poetry env info

Virtualenv
Python:         2.7.17
Implementation: CPython
Path:           /home/larry/Workspace/plurkcore/.venv
Valid:          True

System
Platform: linux
OS:       posix
Python:   /home/larry/.pyenv/versions/2.7.17

~/Workspace/plurkcore(master ✗) poetry config --list
cache-dir = "/home/larry/.cache/pypoetry"
virtualenvs.create = true
virtualenvs.in-project = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/larry/.cache/pypoetry/virtualenvs

@squirrel532
Copy link
Author

It seems that it doesn't respect the configuration.

@finswimmer
Copy link
Member

@etijskens: You have virtualenvs.in-project = true in your config. poetry then creates the venv within the project and calls the folder .venv. The name is hardcoded.

@azdkj532: Ah, I see now. I guess this is a bug. If virtualenvs.in-project = false is set, poetry shouldn't look for .venv within the project folder.

Reopen this issue.

Thanks for reporting!

fin swimmer

@finswimmer finswimmer reopened this Dec 19, 2019
@finswimmer finswimmer added kind/bug Something isn't working as expected area/venv Related to virtualenv management and removed area/docs Documentation issues/improvements labels Dec 19, 2019
@etijskens
Copy link

@finswimmer: thanks for the clarification. So the virtual environment name can only be defined by the user for non-local environments... which I guess is not documented.

@frostming
Copy link
Contributor

When virtualenvs.in-project = true poetry will create venv inside .venv folder, but if there is already a .venv there poetry can also show it in poetry env info, even if virtualenvs.in-project = false. I think it is what user expect when the use poetry to manage old project with a local .venv folder. We can make the directory name configurable though.

@finswimmer
Copy link
Member

finswimmer commented Dec 19, 2019

The more I think about the issue, the less I'm sure that it is a bug. Maybe it's the intended behavior and needs to get documentated as you said @azdkj532. Let's see what @sdispater said.

@squirrel532
Copy link
Author

squirrel532 commented Dec 20, 2019

@frostming Now .venv directly replaces existed virtual environment instead of just appending to environment list. Before useing command poetry env use ... to select their environment, it's OK to use .venv by default. But current behavior causes distress to user while .venv is activated automatically and didn't appear in poetry env list .

IMO, this feature could be changed into

  1. Append .venv into poetry env list automatically.
    1.1 Activate it if the list contains no any other env.
  2. Become one of envs that can be either activated or deactivated by poetry env use ...

@squirrel532
Copy link
Author

Additional information: Poetry use .venv even it's invalid.

larry@squirrelmac /tmp/project$ poetry env info                                                                                                                           130 ↵

Virtualenv
Python:         3.7.1
Implementation: CPython
Path:           NA

System
Platform: darwin
OS:       posix
Python:   /Users/larry/.pyenv/versions/3.7.1/Python.framework/Versions/3.7
larry@squirrelmac /tmp/project$ mkdir .venv
larry@squirrelmac /tmp/project$ poetry env info

Virtualenv
Python:         3.7.1
Implementation: CPython
Path:           /private/tmp/project/.venv
Valid:          False

System
Platform: darwin
OS:       posix
Python:   /Users/larry/.pyenv/versions/3.7.1/Python.framework/Versions/3.7
larry@squirrelmac /tmp/project$ poetry env use 3.7
Creating virtualenv test-FIFGH_JX-py3.7 in /Users/larry/Library/Caches/pypoetry/virtualenvs
Using virtualenv: /private/tmp/project/.venv
larry@squirrelmac /tmp/project$ poetry env info

Virtualenv
Python:         3.7.1
Implementation: CPython
Path:           /private/tmp/project/.venv
Valid:          False

System
Platform: darwin
OS:       posix
Python:   /Users/larry/.pyenv/versions/3.7.1/Python.framework/Versions/3.7

@lvkswrks
Copy link

Hi,
copying over, what I wrote in #967:

I had the expectations, that if virtualenvs.in-project false and virtualenvs.path set to a path, poetry would ignore the in project .venv folder. Treating local .venv differently is imho surprising in this scenario.

The use case we have:

  • local development on e.g. OSX with virtualenvs.in-project=true
  • server / execution environment in a Docker with virtualenvs.in-project=false and virtualenvs.path=/venv
  • execute local code in the Docker by mounting the source code from the local host into the docker

Right now, we work around this issue by exporting the VIRTUAL_ENV=/venv/path/to/bin/python and rm /venv/envs.toml.

@lietu
Copy link

lietu commented Feb 12, 2020

Same issue here. I've got a Windows development machine, but code running in Docker with a mount. The local .venv includes Windows binaries etc., and even with virtualenvs.in-project false and virtualenvs.path configured, poetry keeps complaining about The virtual environment found in /project/mount/.venv seems to be broken. and then tries to recreate the env.

Really counter-intuitive behavior.

@sdispater
Copy link
Member

I agree that this is not an intuitive behavior.

I think we should make a distinction between the virtualenvs.in-project setting is not set (and keep the current behavior of using the local .venv virtual environment in this case) and if it's set explicitly to False.

That way, we make sure that it's possible to tell Poetry to not use the .venv virtual environment.

@finswimmer finswimmer self-assigned this Aug 5, 2020
@abn abn closed this as completed in #2771 Sep 23, 2020
abn pushed a commit that referenced this issue Sep 23, 2020
Before this change, when .venv directory exists  within the project 
root, poetry will use it as the path to the venv regardless whether 
virtualenvs.in-project is set to true or not. This leads to confusion
as described in #1770 and #2756.

With this change poetry will check if virtualenvs.in-project is set to
true if it finds a .venv folder.

This commit also changes the default state of this configuration to be
unset (null), in order to not break any current environments.

Resolves: #1770 #2756
@ccrvlh
Copy link

ccrvlh commented Jun 11, 2021

Exactly same situation as @lvkswrks.
Any news on this?

EDIT: I was using the config wrong, it seems to work by setting poetry config virtualenvs.in-project false && poetry env use python in the Dockerfile - that way I can have an in-project .venv also. Thanks

Copy link

github-actions bot commented Mar 2, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/venv Related to virtualenv management kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants