Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

poetry Virtual environment already activated

Running the following

poetry shell

returns the following error

/home/harshagoli/.poetry/lib/poetry/_vendor/py2.7/subprocess32.py:149: RuntimeWarning: The _posixsubprocess module is not being used. Child process reliability may suffer if your program uses threads.                                                                                                                                                                                    
  "program uses threads.", RuntimeWarning)                                                                                                                                                    
The currently activated Python version 2.7.17 is not supported by the project (^3.7).                                                                                                         
Trying to find and use a compatible version.                                                                                                                                                  
Using python3 (3.7.5)                                                                                                                                                                         
Virtual environment already activated: /home/harshagoli/.cache/pypoetry/virtualenvs/my-project-0wt3KWFj-py3.7

How can I get past this error? Why doesn't this command work?

like image 733
arshbot Avatar asked Mar 07 '20 17:03

arshbot


People also ask

How do you activate a virtual environment poem?

The easiest way to activate the virtual environment is to create a new shell with poetry shell . To deactivate the virtual environment and exit this new shell type exit . To deactivate the virtual environment without leaving the shell use deactivate .

Where are poetry VENV stored?

If not set explicitly, poetry by default will create virtual environment under {cache-dir}/virtualenvs or use the {project-dir}/. venv directory when one is available. If set to true , the virtualenv will be created and expected in a folder named . venv within the root directory of the project.

Does poetry create a virtual environment?

Poetry is also bound to the pyproject. toml file and its path to generate a new environment. poetry will create a new virtual environment but this is not exactly the same as changing just some project deps. This will generate a new environment with just the asked dependencies changed.

How do you delete a virtual environment in a poem?

Run poetry env list (this will show you the venv for that project) Then run poetry env remove whatever-WhATeVs-py3. 9 to delete it.


2 Answers

I'd have to do the following

source "$( poetry env list --full-path | grep Activated | cut -d' ' -f1 )/bin/activate"
like image 56
mr.bjerre Avatar answered Sep 27 '22 19:09

mr.bjerre


poetry shell is a really buggy command, and this is often talked about among the maintainers. A workaround for this specific issue is to activate the shell manually. It might be worth aliasing the following

source $(poetry env info --path)/bin/activate

so you need to paste this into your .bash_aliases or .bashrc

alias acpoet="source $(poetry env info --path)/bin/activate"

Now you can run acpoet to activate your poetry env (don't forget to source your file to enable the command)

like image 23
arshbot Avatar answered Sep 27 '22 18:09

arshbot