Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5164

Troubleshooting • Re: Issues installing OpenCV Virtual Enviroment

$
0
0
Starting with Bookworm, you're not supposed to install packages in the system with pip anymore.

But IF you really, really want to do it, you can do it and all you have to do is to follow the instructions you got when you tried to run sudo pip xxxxxxxxx which was this:
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.

If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.

For more information visit http://rptl.io/venv

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager")
As you see, it tells you both how to do it the old way and how to do it the new way.

This is the new way:

Assuming you're logged in a user pi

Code:

$ # go to home folder$ cd /home/pi$ # create a directory for the project$ mkdir projdir$ # cd into new project$ cd projdir$ # create a python virtual environment$ python3 -m venv  projectenv --system-site-packages$ # activate the virtual environment$ source projectenv/bin/activate$ # install whatever python packages you need$ pip install python_module_name_you_are_trying_to_install
Later, when you start a new terminal window and need to work on the project again, you need to activate it in that terminal window too

Code:

$ # go to home folder$ cd /home/pi$ # cd into new project$ cd projdir$ # activate the virtual environment$ source projectenv/bin/activate
Using virtualenv/virtualenvwrapper should be the same as with the steps you need to take, but I don't use it so I don't know for sure and if you have issues with it, you should ask them maintainers here: https://github.com/pypa/virtualenv/issues

Statistics: Posted by memjr — Mon Apr 08, 2024 7:59 pm



Viewing all articles
Browse latest Browse all 5164

Trending Articles