Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The virtual environment found seems to be broken | python poetry

I am following the following link to install RASA on my system: https://github.com/RasaHQ/rasa But unfortunately while trying to install the dependencies or any of the following poetry commands which are written in Makefile,

$poetry run
$poetry install

I am getting following error:

enter image description here

Seems like there is some issue in virtual environment setup but don't know how I can fix. Following is the stack trace:

$ make install
poetry run python -m pip install -U 'pip<20'
The virtual environment found in /home/kamaldeep/.cache/pypoetry/virtualenvs/rasa-LHgLSZoI-py3.6 seems to be broken.
Recreating virtualenv rasa-LHgLSZoI-py3.6 in /home/kamaldeep/.cache/pypoetry/virtualenvs/rasa-LHgLSZoI-py3.6

[CalledProcessError]
Command '['/home/kamaldeep/.cache/pypoetry/virtualenvs/rasa-LHgLSZoI-py3.6/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
Makefile:43: recipe for target 'install' failed
make: *** [install] Error 1
like image 807
Kamaldeep Singh Avatar asked Apr 21 '20 19:04

Kamaldeep Singh


People also ask

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 activate virtual environment in Poetry?

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 .

What is the point of a virtual environment?

A virtual environment is simply a tool that separates the dependencies of different projects by creating a separate isolated environment for each project. These are simply the directories so that unlimited virtual environments can be created.

How do you remove an environmental poem?

Deleting the environments You can delete more than one environment at a time. Use the --all option to delete all virtual environments at once.


2 Answers

In case if you get error of broken virtual environment like

The virtual environment found in /home/kamaldeep/.cache/pypoetry/virtualenvs/rasa-LHgLSZoI-py3.7 seems to be broken

Then install venv in the respective python package like python3.6, python3.5. In my case, I am using python 3.7

sudo apt-get install python3.7-venv

Other way is to disable virtual environment

poetry config virtualenvs.create false
like image 109
Kamaldeep Singh Avatar answered Dec 28 '22 08:12

Kamaldeep Singh


Kamaldeep Singh's answer was what I needed: sudo apt-get install python3.7-venv.

A couple of details to add to complete the process (this is for those like me who aren't so comfortable juggling package versions and are also perhaps new to using Poetry) (adjust for the Python version you want to work with):

  • Go to your project directory and start Poetry (if you're not already there); get rid of the broken virtual environment,

     cd your_project_directory
     poetry shell
     poetry env remove python3.7
    
  • Leave Poetry (I found Poetry got muddled otherwise),

     exit
    
  • Did you already install python3.7-venv as per Kamaldeep Singh's answer? Do it now if not (assuming you're on a Debian/Ubuntu-based system),

     sudo apt install python3.7-venv
    
  • Re-enter Poetry,

     poetry shell
    
  • Recreate the environment now that python3.7-venv is installed,

     poetry env use python3.7
    
  • Add required dependencies for your project,

     poetry install
    

That's it, you should now be ready to work on your project in the new Python version. Poetry CLI documentation for more options...

(update: One bit of strangeness: I found exiting and re-entering poetry shell one more time after poetry install was necessary for pytest to be found. This leave Poetry and re-enter it step (again) feels very clumsy, maybe someone here can explain why that might be necessary in comments?)

like image 34
Andrew Richards Avatar answered Dec 28 '22 09:12

Andrew Richards