17

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

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

I then installed pyserial with:

$sudo pip3 install pyserial

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

ImportError: No module named serial

The error is at the line which says

import serial

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'>

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.

Thanks.

EDIT: 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.

user3587244
  • 173
  • 1
  • 1
  • 7
  • Can you execute `pip3 list` and paste the result here? Also, is `PYTHONPATH` set? – Trein Apr 30 '14 at 03:27
  • @Trein pip3 list gives me the following: "distribute (0.6.49) pip (1.5.4) pyserial (2.7) setuptools (3.4.4) " I am not quite sure what I am doing, but I tried setting PYTHONPATH with a tutorial I found. Here's what I did: export PYTHONPATH=$PYTHONPATH:/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages It didn't fix it though. I get the sense that this is not too complicated a problem, but it's giving me a huge headache. Thanks! – user3587244 May 01 '14 at 20:13
  • Everything seems to be correct. My last guess is that `Python Launcher` is using the incorrect interpreter (maybe it is using Python 2.7). Go to preferences and check it out. – Trein May 01 '14 at 21:35

3 Answers3

12

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
BitByte_Bake
  • 939
  • 1
  • 9
  • 12
1

First use the two commands (which pip & which python) to get the exact path of the python and pip commands. After this only you will be able to determine the exact issue.

Shrey
  • 1,242
  • 1
  • 13
  • 27
  • /Library/Frameworks/Python.framework/Versions/3.3/bin/pip which python gives me python 2.7, but I am executing it through python launcher 3. Could that be the problem? – user3587244 May 01 '14 at 19:57
  • I am not sure but this could be issue. Try using relative path for python command so that it picks up your python 3.x. Like instead of using **python** you should use **/xyzpath_for_python3.x/python** – Shrey May 02 '14 at 05:00
1

For me, the problem was solved by running the script importing serial in a user (not administrative) context. Windows, not Mac, so YMMV.

Jostikas
  • 196
  • 1
  • 13
  • In hindsight, that probably had something to do with the proliferation of Python installs in the computer, with the user console resolving to a different installation compared to the administrative one. – Jostikas Jul 12 '21 at 12:00