ejwjohn
Posts: 149
Joined: Fri Apr 01, 2016 9:14 am

Magpi 136 Python on Raspberry Pi - Virtual Environment

Thu Dec 07, 2023 9:31 am

With ref to the article, i fully understand the logic behind this latest change but as a learning novice i am struggling on one aspect of deploying this on my RPi 5 with Bookworm.

I generally use Thonny as my IDE, and within the article it discusses how to set up the new environment under Thonny......BUT how do i install, using pip, within the terminal any additional libraries i need.???

I need to activate the new Thonny environment within the command line but how???
The source command to activate doesn't work on my system, so i am assuming i have missed something very fundamental in this set up article on how i do this .

Thanks for your help.

JohnW

lucyhattersley
Posts: 63
Joined: Tue Aug 04, 2015 5:05 pm

Re: Magpi 136 Python on Raspberry Pi - Virtual Environment

Thu Dec 07, 2023 10:50 am

Did you check out the "Using Thonny editor" box on page 53
Thonny is our recommended IDE (integrated development environment) when working with Python on Raspberry Pi. By default, Thonny uses the system Python.
However, you can switch to using a Python virtual environment by clicking on the interpreter menu located at the bottom right of the Thonny window. Clicking on this will offer you a menu to select a configured interpreter or to Configure
an interpreter.
Choose Configure interpreter and click ‘New virtual environment’. An alert window will appear that says “After clicking ‘OK’ you need to choose an empty directory, which will be the root of your new virtual environment”.
Click OK and choose ‘Documents’ in the sidebar or the Files app. Click ‘Create Folder’ and enter “my_project” as the folder name and click OK. Wait for the ‘Creating virtual environment’ window to appear, and close. Check that the Python executable selection contains “my_project/bin/ python3” and click OK.
You can now install packages into your virtual machine using Tools > Manage packages. If you cannot see Tools then first click on ‘Switch to regular mode’ and restart Thonny.
Search for ‘buildhat’ in the Manage packages window and click ‘buildhat’ in the search results window. Click ‘install’ to add the package to your virtual environment.

ejwjohn
Posts: 149
Joined: Fri Apr 01, 2016 9:14 am

Re: Magpi 136 Python on Raspberry Pi - Virtual Environment

Thu Dec 07, 2023 11:08 am

Hello,


Yes i did and i had just been reading it again, and noticed that i had "subconsciously" (my excuse) ignored the ref to Tools and Mange Packages.

So got passed that hurdle and loaded up some libraries for a quick test and I have several errors reported when i am trying to access the GPIO pins, I am still investigating but the errors appear to suggest that there is a Bad Pin Factory?? no idea what that means..... but i did read somewhere that Bookworm has remapped all the GPIO pins so not sure if that's linked to my issues.

Thanks

JohnW

raspberry400
Posts: 94
Joined: Wed Feb 01, 2023 8:29 pm
Location: Montreal,Quebec

Thu Dec 21, 2023 12:14 pm

so i use Visual studio code on a raspberry pi 400 and ifound a workaround by jeffgeerling for the pip error message if you dont install in virtual environements so bascalyy yu enter sudo rm /usr/bin/your_path_to_python/EXTERNALLY_MANAGED but each time i update python i ned to re run the command
Im a kid of 11 years... dont overjudge me!

Return to “The MagPi”