Using opencv and flask

Hi,

I’ve finally managed to get opencv working using the Tkinter example repl. Now I want to add Flask to serve the results of my image processing, but this repl won’t allow me to install flask. Clicking ‘install’ gives a small modal saying ‘flask installed’ but it doesn’t show in the package list and I still get an error trying to import it.

If I use poetry add flask in the shell I get this error:

  AttributeError

  'HTTPResponse' object has no attribute 'strict'

  at venv/lib/python3.8/site-packages/cachecontrol/serialize.py:54 in dumps

The standard python repl has Flask, but well documented (plenty of threads here) issues installing opencv!

How can I create a repl with both flask and opencv packages installed?

Many thanks.

Hi, @daisyfreyja. Welcome to the forums!

It sounds like you are running into some issues with dependency conflicts when trying to install both Flask and OpenCV in the same Repl. One possible solution is to use a “virtual environment” to manage your Python dependencies.

Here’s a general overview of how you might do this:

  1. Create a new Repl and install the virtualenv package by running pip install virtualenv.
  2. Create a new virtual environment by running virtualenv venv.
  3. Activate the virtual environment by running source venv/bin/activate.
  4. Install the packages you need (Flask and OpenCV, for example) using pip. Note that when you install packages in the virtual environment, they will only be available within that environment, so you won’t have to worry about dependency conflicts.
  5. In the Repl interface, click on the “Shell” button in the top menu bar and run the command python.
  6. Import the packages you need (Flask and OpenCV, for example) and write your code.

When you’re finished working with the virtual environment, you can deactivate it by running deactivate in the shell.

Keep in mind that this is just one possible solution, and there may be other ways to address dependency conflicts (such as using a Docker container or a different virtual environment management tool). However, using a virtual environment is a common and relatively simple approach that may be worth trying.

This seems like an error I’ve already fixed, see this:

1 Like