Reputation: 19
Dependencies for pyserial already installed, calling pyserial isn't recognized in python
Maxs-MacBook:~ grax$ sudo pip install pyserial
The directory '/Users/grax/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/grax/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: pyserial in /Library/Python/2.7/site-packages
Maxs-MacBook:~ grax$ python
Python 2.7.15 (default, May 2 2018, 00:53:27)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.29.1] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyserial
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Import Error: No module named pyserial
What should I do?
Upvotes: 1
Views: 8468
Reputation: 4561
The python module is called serial
even though you call pip pyserial. Confusing, yes.
import serial
The other issue may be that the instance of python you're using isn't the same as the one pip
is installing for.
See where pip installed the module:
$ pip show pyserial
Name: pyserial
Version: 3.4
Summary: Python Serial Port Extension
Home-page: https://github.com/pyserial/pyserial
Author: Chris Liechti
Author-email: [email protected]
License: BSD
Location: /Library/Python/2.7/site-packages
Because your Location is /Library/Python2.7...
pip appears to be installing in the system directory.
However, the version of python you're using (Python 2.7.15) is not the one shipped with MacOSX, so it's probably looking for the python modules somewhere else.
$ python
>>> import sys
>>> print sys.path
The version of pip
is most likely not installing there. (pip is not native to MacOS, so it may be using /usr/local/bin/python
and /usr/local/lib/python2.7/site-packages
.
You can force pip to install somewhere else using --target
option:
$ sudo pip install --target /usr/local/lib/python2.7/site-packages pyserial
Which will put the serial
module in the location your python is looking.
Upvotes: 2