How To Fix Error Loading RPi.GPIO Python Library On Your Brand New Raspberry Pi 2
来源:互联网 发布:数据库应急预案 编辑:程序博客网 时间:2024/05/16 08:54
If you’ve just setup your shiny new Raspberry Pi 2 and tried to run a Python script that accesses GPIO you might be sad to see an error like this:
Traceback (most recent call last):
File “”, line 1, in
RuntimeError: This module can only be run on a Raspberry Pi!
Don’t worry! The version of the RPi.GPIO Python library shipped with the latest Raspbian OS doesn’t support the Pi 2 out of the box, but you can install a later version to fix the problem.
First check what version of the RPi.GPIO library is currently available from Python’s package index here. Version 0.5.9 and below unfortunately are not compatible with the Pi 2, however version 0.5.10 and above should work.
If you see version 0.5.10 or greater on the site then you can install it with a few simple commands. First connect to your Pi 2 in an SSH / terminal session (check out this guide if you’re new to Linux & the Pi 2, or try the awesome new Pi Finder to get a terminal open easily). Once connected to your Pi 2 run these commands to update RPi.GPIO to the latest version:
sudo apt-get update
sudo apt-get install python-pip
sudo pip install -U RPi.GPIO
Answer yes to any questions that come up about downloading and installing software. After everything finishes you should be all set and ready to use the RPi.GPIO library on the Pi 2. Remember this method will only work once the RPi.GPIO library on the Python package index is updated to version 0.5.10 or greater!
As of the time of this writing the 0.5.10 version hasn’t been put up on the Python package index yet, so as a workaround you can manually download the RPi.GPIO library from its home on Sourceforge and install it with a few simple commands. Don’t worry this only takes a few more commands than installing from the Python package index. Connect to your Pi 2 in a terminal session as mentioned above, but this time execute these commands:
sudo apt-get update
sudo apt-get install build-essential python-dev python-pip mercurial
cd ~
hg clone http://hg.code.sf.net/p/raspberry-gpio-python/code raspberry-gpio-python-code
cd raspberry-gpio-python-code
sudo python setup.py install
Answer yes to any questions about installing packages. After running the last command above you should see some text scroll by as the library is compiled and installed. If it successfully installs you should see a message like “Writing /usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.10a.egg-info” as the last output. At this point you’re all set to use the RPi.GPIO library on your Pi 2! If you see an error message carefully check all the commands above were successfully executed and try again.
I gave the latest 0.5.10a version of the RPi.GPIO library a quick test and it seems to work great for accessing GPIO on the Pi 2. Since the Pi 2 is brand new you might run into issues or problems with libraries like RPi.GPIO. The best place to go for help are the Raspberry Pi forums–good luck and enjoy your Pi 2!
- How To Fix Error Loading RPi.GPIO Python Library On Your Brand New Raspberry Pi 2
- python GPIO安装 How To Fix Error Loading RPi.GPIO Python Library On Your Brand New Raspberry Pi 2
- Raspberry Pi Blink(Python RPi.GPIO)
- How to config WIFI on Raspberry PI
- Raspberry Pi+Python+ GPIO
- How to Fix Grub Loading Error
- How to build a cross compiler for your Raspberry Pi
- 树莓派 raspberry pi GPIO python
- 【RPi树莓派使用指南】An Introduction to Raspberry Pi
- raspberry Pi on Archlinux, Install wiringPi , GPIO
- Raspberry Pi: Use ssh to talk with your Raspberry Pi
- How to fix the “msvcrt-ruby18.dll is missing from your computer” error message in Ruby on Rails
- Raspberry Pi: How to set up WiFi
- How to fix a "Duplicated Symbols" error on binary files
- How to fix “System program problem detected” error on Ubuntu
- How to fix “System program problem detected” error on Ubuntu
- How to fix a "Duplicated Symbols" error on binary files
- How to install or upgrade UV4L on Raspbian (for the Raspberry Pi)
- 常用HTML字体标签页
- UI基础之UIview,UILabel,UIWindow
- android ViewPager 禁用/开启 滑动切换功能
- 大数加法(补零)
- 插入排序(直接插入和Shell排序)
- How To Fix Error Loading RPi.GPIO Python Library On Your Brand New Raspberry Pi 2
- Maven使用
- HDU 1754 I Hate It (线段树 单点替换, 区间最值)
- tomcat结合nginx使用小结
- 黑马程序员--继承、抽象类、接口
- 多数求最大公倍数
- MySql乱码问题
- jsp+mysql:Unknown column 'a' in 'field list'
- Codeforces #316 E Pig and Palindromes DP