adafruit / Adafruit_Blinka

Add CircuitPython hardware API and libraries to MicroPython & CPython devices
https://learn.adafruit.com/circuitpython-on-raspberrypi-linux
MIT License
439 stars 328 forks source link

Blinka is not installed in Anaconda active environment #648

Closed RnoldR closed 10 months ago

RnoldR commented 1 year ago

I installed blinka according to the instructions found at: https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi. Next I tried to run the blinkatest.py script that can be found in the URL above. This crashes at the first line (import board) because board cannot be found.

When I run the test as sudo python blinkatest.py it works correctly. The same when I disable anaconda initialization in my .bashrc script and run as python blinkatest.py. So I figure the library scripts are not installed in the environment libraries but in some global library. Is this the expected behavior? If so, is there a workaround? Or should I use adafruit products without blinka?

I have a raspberry 4 with the latest 64-bit version of raspberry os and the latest version of anaconda (22.9.0) for arm. I use environments because projects may have conflicting demands.

tekktrik commented 1 year ago

I think conda may have it's own package location. Are you activating the Anaconda virtual environment before pip installing>?

RnoldR commented 1 year ago

I activated the anaconda environment before pip by installing. The way Anaconda uses its virtual environments is the same like venv and is recognised by pip. What is atypical for the Blinka installing is the use of sudo. As far as I know that implies root takes over the install process and that probably the libraries land on a non-standard spot for the user (but probably standard for user root).

tekktrik commented 1 year ago

You could try which pip and sudo which pip to see if it's using a different pip.

makermelissa commented 1 year ago

What happens when you try installing Blinka without using sudo by typing pip3 install Adafruit-Blinka?

anguselheimStudios commented 1 year ago

Using sudo with pip installs a package globally when not being used with a virtual environment. Not sure how it would behave with conda.

makermelissa commented 10 months ago

Feel free to reopen this if needed. I know that Blinka can be installed without using sudo by running pip3 install --upgrade adafruit-blinka. The install script on the page you linked to has you run needs to be run as sudo because it sets things like enabling I2C and SPI and running apt-get, which need sudo. However, when it runs the pip command, sudo is not used (see https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/main/raspi-blinka.py#L83). To install in a virtual environment you should install with pip only. I have added an alert to the learn guide to indicate this.

makermelissa commented 10 months ago

I'm working on some changes so the Raspi Blinka Script will install as a user rather than as sudo. I opened an issue at https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/issues/259.