已经安装了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
我该怎么办?
答案 0 :(得分:1)
即使您将pip pyserial称为python模块,也称为using fruittyPie.Models.DataRepositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace fruittyPie.Models.Other
{
public class CategoryMenu : ViewComponent
{
private readonly ICatagoryRepository _catagoryRepository;
public CategoryMenu(ICatagoryRepository catagoryRepository)
{
_catagoryRepository = catagoryRepository;
}
public IViewComponentResult Invoke()
{
var catagory = _catagoryRepository.Catagories.OrderBy(p => p.CatagoryName);
return View(catagory);
}
}
}
。令人困惑,是的。
serial
另一个问题可能是您使用的python实例与import serial
要为其安装的python实例不同。
查看pip在何处安装了模块:
pip
因为您的位置为$ 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: cliechti@gmx.net
License: BSD
Location: /Library/Python/2.7/site-packages
点,似乎正在系统目录中安装。
但是,您使用的python版本(Python 2.7.15)不是MacOSX随附的版本,因此它可能正在其他地方寻找python模块。
/Library/Python2.7...
$ python
>>> import sys
>>> print sys.path
的版本很可能不安装在此处。 (pip不是MacOS固有的,因此可能正在使用pip
和/usr/local/bin/python
。
您可以使用/usr/local/lib/python2.7/site-packages
选项强制将pip安装在其他位置:
--target
这会将$ sudo pip install --target /usr/local/lib/python2.7/site-packages pyserial
模块放在您的python正在查找的位置。