Ubuntu12.04 自安装python3.3中头文件Python.h路径:usr/local/python3.3/include/python3.3m
Ubuntu12.04 自带的Python2.7中头文件Python.h路径:usr/ include/python2.7
Ubuntu12.04 自安装python3.3解释器Python路径:usr/local/python3.3/bin
Ubuntu12.04 自带的Python2.7解释器Python路径:usr/ bin
但默认解释器是python2.7,所以无论在哪个目录下输入python都是python2.7(可能是在安装python3.3时建立了连接关系)
现在将python2.7备份:sudo cp /usr/bin/python ./pythonback
删除原python:sudo rm usr/bin/python
建立新连接 sudo ln -s /usr/local/python3.3/bin/python3.3 /usr/bin/python
之后输入python默认的就是python3.3解释器了,如果想使用python2.7可以在/usr/bin目录下使用pythonback
如果不想更改默认连接,则可以在/usr/local/python3.3/bin目录下使用python3.3
在ubuntu12.04上:
spi源文件名:spi.c 测试文件名:spi_test.py
编译2.7版spi.c:
gcc -fpic -c -I/usr/local/python3.3/include/python3.3m spi.c =>spi.o(用Python3.3的头文件python.h)
gcc -shared -o spi.so spi.o =>spi.so(产生共享库spi.so文件)
python spi_test.py
编译3.3版spi.c
gcc -fpic -c -I/usr/include/python2.7 spi.c
gcc -shared -o spi.so spi.o
pythonback spi_test.py
在raspberry上:
nano使用:
sudo nano /etc/hosts
完成后按ctrl+x退出,按y保存,回车,OK
raspberry找不到spidev0.0和spidev0.1的解决办法:
修改系统配置
都注释掉,修改为:
修改加载模块
改为:
主要是增加 spidev
重启之后,/dev/中会多出两个设备 spidev0.0 与 spidev0.1, 没有出现的话请google排错。
具体参见:http://www.shumeipai.net/forum.php?mod=viewthread&action=printable&tid=19410
编译python2.7代码:
raspberry的python.h路径:/usr/include/python2.7
raspberry的python2.7解释器路径:/usr/bin python2.7
pi@raspberrypi:~/Documents/python_spi/python_spi_2$ gcc -fpic -c -I/usr/include/python2.7 spi.c
pi@raspberrypi:~/Documents/python_spi/python_spi_2$ gcc -shared -o spi.so -I/usr/include/python2.7 spi.o
pi@raspberrypi:~/Documents/python_spi/python_spi_2$ python spi_test.py
#raspberry的python3.2解释器路径:
#pi@raspberrypi:/usr/bin$ python3.2mu
#Python.h文件路径:/usr/lib/pypy-upstream/include/
python3.3的python.h文件路径:/usr/local/Python-3.3..2/include/python3.3m/
python3.3解释器python3.3文件路径:/usr/local/Python-3.3..2/bin
将/usr/local/Python-3.3..2/bin添加到PATH路径后,在该路径下即可使用python3.3解释器
pi@raspberrypi:/usr/local/Python-3.3..2/bin$ python3.3
编译:
pi@raspberrypi:~/Documents/python_spi/python_spi_3$ gcc -fpic -c -I/usr/local/Python-3.3..2/include/python3.3m spi.c
pi@raspberrypi:~/Documents/python_spi/python_spi_3$ gcc -shared -o spi.so -I/usr/local/Python-3.3..2/include/python3.3m spi.o
pi@raspberrypi:~/Documents/python_spi/python_spi_3$ /usr/local/Python-3.3..2/bin/python3.3 spi_test.py