Search code examples
packagedependenciesvirtualenvpython-poetry

problem activating virtual env inside project folder using poetry: cannot deactivate current virtual env


I have a global virtual env (my_env) and have been developing all my projects in it. Now I have developed a new project, also in my_env, and I want to use poetry to create a new, project-specific env in the project folder (the default env of which is my_env).

I did the following in the terminal:

poetry init --no-interaction
poetry config virtualenvs.in-project true
poetry install 

But this installs all dependencies in my_env, and does not create a new .venv folder inside my project directory. I guess I have to deactivate my_env in my working directory before doing all of the above, but source deactivate my_env does not work.

Can anyone tell me what I am doing wrong?


Solution

  • Assuming poetry is globally available (installed through pipx for example), pyenv shell system will allow to run a shell without an active pyenv environment

    Then you can

    poetry config --list  # verify create and in-project are set to true
    poetry new project_name  # create project
    poetry install  # install venv and dependencies