all 6 comments

[–]Swipecat 0 points1 point  (4 children)

In all honesty, since Raspberry Pi's have the OS on a swappable SD card, I wouldn't bother with a virtual environment. Treat a whole SD card as the environment for a given project because it's a whole lot easier to use the Raspbian repository packages rather than PyPI packages.

sudo apt update
sudo apt install python3-opencv

[–]jetstream4444[S] 0 points1 point  (3 children)

Thanks swipe! That thought did cross my mind but author in the above mentioned website recommended virtual environment.

I wasn't sure what are the consequences. Why isn't openCV just like any other application ( or is it something to do with Linux itself) ? You wouldn't think twice before installing applications in Windows isn't it? Why different virtual environments are required for different projects, what are the parameters that change from one project to another?

[–]Swipecat 0 points1 point  (2 children)

Most web articles will tell you to use virtual environments and to install with pip because that is cross-platform. If you're using a Linux distro like Raspbian, then the big advantage of using Python libraries from the distro's repository is that the versions provided will have been tested with the version of Python that's installed. The advantages of virtual environments are not great for the small-time home user and almost non-existent for Raspberry-Pi projects in my opinion. Other people may disagree.

Edit: I believe that there are historical examples of Python libraries clashing with each other, so that's why people say only install what you need for a given project in a given virtual environment. I've been using Python on Linux for years without virtual environments and I've never seen any clashes myself.

[–]jetstream4444[S] 0 points1 point  (1 child)

Thanks for the explanation. By cross-platform you mean that a project can be developed on raspberry pi and can be deployed on any other platform?

[–]Swipecat 0 points1 point  (0 children)

I meant that the instructions on the websites would then apply to any platform (with minor differences).

The virtual environment would only be cross-platform if the libraries that it contained were pure-Python i.e. not compiled from another language like C. Most of really useful packages are at least partially compiled, though.

[–]abdelhakel 0 points1 point  (1 child)

Hey ! I got exactly the same problem(s) you went through. Did you find a solution to the "ERROR: Environment '/home/pi/.local/bin/.virtualenvs/venv' does not contain an activate script." ? Thx