导入pyserial/serial python无法识别,但已安装依赖项[Mac]

2024-06-16 10:06:20 发布

您现在位置:Python中文网/ 问答频道 /正文

pyserial的依赖项已经安装,python无法识别调用pyserial的依赖项

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

我该怎么办?在


Tags: piporandthelibrarysudousersdirectory
1条回答
网友
1楼 · 发布于 2024-06-16 10:06:20

python模块被称为serial,即使您调用了pip pyserial。令人困惑,是的。在

import serial

另一个问题可能是您使用的python实例与pip正在为其安装的实例不同。在

请参阅pip安装模块的位置:

^{pr2}$

因为您的位置是/Library/Python2.7...,pip似乎正在系统目录中安装。在

但是,您使用的python版本(python2.7.15)不是MacOSX附带的版本,所以它可能在其他地方寻找python模块。在

$ python
>>> import sys
>>> print sys.path

pip的版本很可能安装在那里。(pip不是MacOS自带的,所以它可能使用/usr/local/bin/python和{}。在

您可以使用 target选项强制pip安装到其他地方:

$ sudo pip install  target /usr/local/lib/python2.7/site-packages pyserial

这将把serial模块放在python正在查找的位置。在

相关问题 更多 >