DC and Stepper Motor HAT error

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Post Reply
User avatar
sfdonut
 
Posts: 2
Joined: Sun Apr 09, 2023 4:09 pm

DC and Stepper Motor HAT error

Post by sfdonut »

I’m very new to the Raspberry Pi and coding in general, so please forgive me if I missed the obvious.

I have a Raspberry Pi with an Adafruit DC and Stepper Motor HAT for the Raspberry Pi. I’m installing the software, and when I enter the command line “sudo pip3 install adafruit-circuitpython-motorkit” I get an error: externally-managed-environment.  How can I fix this?

I currently have a Raspberry Pi 5, and I've followed the directions via this link: https://learn.adafruit.com/adafruit-dc- ... g-software  It worked fine on my Raspberry Pi 4 with an older OS. I don’t remember what the older OS version was because I have since updated it. I’m currently using PI OS (64-bit). Released :2023-12-05.

Thanks for your help.

User avatar
Franklin97355
 
Posts: 23883
Joined: Mon Apr 21, 2008 2:33 pm

Re: DC and Stepper Motor HAT error

Post by Franklin97355 »

I Googled the error and this might help:
In most cases, the easiest method of getting around the externally-managed-environment error is installing the Python package using the system package manager.

In this section, we use apt on Ubuntu, but the process is similar for other distributions and system package managers.

Let’s begin by installing the arrow package. The name of the system package may be different than the one that pip uses. Therefore, we first attempt to identify the correct package:

$ apt list -v '*arrow*'
...
python3-arrow/lunar 1.2.3-1 all
Python3 library to manipulate dates, times, and timestamps
Copy
In this example, we use apt with list ‘*arrow*’ to search for packages containing arrow in their name. Additionally, we use the -v flag to print information about the listed packages.

Typically, Python packages are named python3-<package> in Ubuntu. In this case, the package name is python3-arrow.

Next, we install python3-arrow using apt:

$ sudo apt install python3-arrow
...
Setting up python3-arrow (1.2.3-1) ...
Copy
Now, arrow is installed globally. A benefit to this method is that updating our system updates this package as well.

User avatar
edgjr
 
Posts: 136
Joined: Mon Jan 16, 2012 6:18 pm

Re: DC and Stepper Motor HAT error

Post by edgjr »

You shouldn't be installing Blinka and Adafruit packages system wide (any more) -- there's an updated guide for using virtual environments: https://learn.adafruit.com/circuitpytho ... rypi-linux

User avatar
sfdonut
 
Posts: 2
Joined: Sun Apr 09, 2023 4:09 pm

Re: DC and Stepper Motor HAT error

Post by sfdonut »

I’ve followed the steps in the link you sent. Again I’m new to this so I might be misunderstood the directions on the website.

The first step is to update your Pi and Python; that part worked fine. Then I setup the virtual environment, which worked, so I was able to run the automated install. I think that’s the last step that I need to follow on this page. https://learn.adafruit.com/circuitpytho ... spberry-pi

After that, I used Thonny to run a motor script. The top of the script starts with:

import time
import board
from adafruit_motor import stepper
from adafruit_motorkit import MotorKit

The script doesn’t work. I got the following error from Thonny:

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<string>", line 3, in <module>
ModuleNotFoundError: No module named 'board'
>>>

Does this mean that I haven’t installed something correctly? It looks like it doesn’t understand the line-import board. 

Any help would be appreciated.

Post Reply
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”