Raspberry Pi, cannot import odrive on python


we are trying to program our ODrive Pro to control a DC Brushless motor, more details in our earlier query ODrive Pro Connection to MITSUBA M2096D-Ⅲ Motor - Support / ODrive Pro Support - ODrive Community (odriverobotics.com). [That problem has been solved]

When we ran a sample ODrive code on visual studios, it says that the odrive module is not found, as seen in the photo attached. We ran a “pip list” function in the terminal and found that the odrive module is available in our system, despite what Visual Studio Code says.
Would appreciate some insight on this matter, thank you for taking the time to read our post.

Looks like you’re using Python 2? ODrive is currently only compatible with Python 3. Where did you get that example code from?

Hello. We got the sample code from odrive · PyPI . We extracted the zip file into our main folder. The sample code is located under “odrive python package/odrive-0.6.8-py3-none-any/odrive-0.6.8.data/scripts” and we opened “odrive_demo.py”.

You should install it using pip or your system package manager - you can see this page for installation instructions odrivetool — ODrive Documentation 0.6.9 documentation

We have updated python to the latest ver. However we have been getting the “error: externally-managed-environment”. We bypassed this via creating a virtual environment named “myenv”. From there we installed the odrive into the virtual environment. We did not do step 5 as we are using the Raspberry Pi OS. We are still unable to invoke the odrive library.

We got an error of “ModuleNotFoundError: No module named ‘odrive’”

Ok. After some chatgpt-ing we managed to fix the problems and it is now working.

Glad to hear you found a fix! Would you mind filling me in on what got it working?

Sure. After some chatgpt-ing and internet searching, we managed to run the program on Python3. The process goes something like this:

So first, make a virtual environment using

python3 -m venv myenv

and to activate the virtual environment using

source myenv/bin/activate

After that, we can download / update the drive package

pip install odrive

Then, we could start programming in Python. Sample Code:

import odrive

# Connect to ODrive
odrv0 = odrive.find_any()

#Output the most simple number
print("Odrive Voltage", odrv0.vbus_voltage)

We need to specify the path to the Python file using

cd /.../myenv

We encountered a slight problem with permission issues. To check for permissions, use

ls -l filename.py

At first we got

 -rw-r--r-- 1

Which is wrong as it cannot be executed. We could read and write in the file, but it won’t execute. To fix this, we use

chmod +x filename

If all goes as plan, we should be able to execute the program using Python3 via the console using

python3 filename.py

Something like this. There might be some missing steps but this is the most I could remember.