ImportError:没有名为串行的模块

ImportError:没有名为串行的模块

问题描述:

我有一个用Python 3编写的脚本,安装了3.3.5,每次尝试运行该脚本时,都会从终端收到此错误.我正在使用Mac OSX 10.7.5

I have a script written in Python 3 with 3.3.5 installed, and I am getting this error from the terminal whenever I try to run it. I am using a Mac, OSX 10.7.5

我已经为python 3安装了pyserial(使用pip).为此,我首先使用以下命令安装了pip:

I have already installed pyserial (using pip) for python 3. In order to do this, I first installed pip using:

$ curl -O http://python-distribute.org/distribute_setup.py
$ sudo python3 distribute_setup.py
$ curl -O https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py
$ sudo python3 get-pip.py

然后我将pyserial安装为:

$sudo pip3 install pyserial

我使用Python启动器运行脚本,但出现错误:

I run the script with Python Launcher and I get the error:

ImportError: No module named serial

错误所在的行是

import serial

我在/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages中找到了pyserial.我真的很沮丧,不知道为什么会收到这个错误.

I located pyserial in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages. I am really stumped and have no clue why I am getting this error.

我在终端机中尝试了以下操作:

I tried the following in Terminal:

$ python3
>>> import serial
>>> serial
<module 'serial' from '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/serial/__init__.py'>

对我来说,目录似乎没有问题.这是一个合理的假设,因为当我在命令行中尝试使用Python时,Python会立即浏览该目录,还是在运行脚本时会有所不同?

To me it looks like there isn't an issue with the directory. Is that a fair assumption, since Python instantly looks through that directory when I try it with the command line, or is it different when I'm running a script?

我对所有这些都是新手,因此,我们将不胜感激任何帮助和耐心.

I'm very new to all of this so any sort of help and patience would be hugely appreciated.

谢谢.

对于其他任何有类似问题的人,我没有真的对其进行修复,但是我通过使用PyDev插件在Eclipse中运行程序来解决了该问题.如果您愿意的话,对我来说就像一个魅力.

For anyone else looking at this having a similar problem, I didn't really fix it, but I worked around it by just running my program with eclipse using the PyDev plugin. If that's an option for you, worked like a charm for me.

在默认使用python 2.7的ubuntu 14.4上,我通过以下命令为python3(我的IDE实际使用的)安装了pyserial:

On my ubuntu 14.4 with python 2.7 as default, I installed pyserial for python3 (which my IDE is using actually) with the help of following command:

sudo apt-get install python3-serial