简体   繁体   English

安装的Python模块无法导入

[英]Installed Python Modules Can't Be Imported

I have multiple indications that my python modules are installed but several cause 'No module named..' exceptions. 我有多种迹象表明我的python模块已安装,但有几种导致“未命名模块..”异常。 For example... 例如...

root@raspberrypi:~# pip install pyfingerprint --no-cache-dir
Collecting pyfingerprint    
Downloading https://www.piwheels.org/simple/pyfingerprint/pyfingerprint-0.1-py3-none-any.whl
Requirement already satisfied: pyserial in /usr/local/lib/python3.5/dist-
packages (from pyfingerprint)
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (from 
pyfingerprint)
Installing collected packages: pyfingerprint
Successfully installed pyfingerprint-0.1

Then, the module is nowhere to be found... 然后,该模块无处可寻...

root@raspberrypi:~# python
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyfingerprint
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'pyfingerprint'

Note also, that the dependent modules in the install above are listed as satisfied, but importing them also fails... 另请注意,上面安装中的相关模块被列出为满意,但是导入它们也失败...

>>> import pyserial
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'pyserial'
>>> import Pillow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'Pillow'

When I check that they exist, pip agrees... 当我检查它们是否存在时,点子同意...

pip freeze

...
Pillow==4.0.0    
...
pyfingerprint==0.1
...
pyserial==3.4
...

The problem is not limited to this install. 问题不限于此安装。 There are numerous modules that pip says exist fail on import. pip说有很多模块在导入时会失败。 Others are just fine. 其他都很好。

I've tried everything in the following SO post, to no avail... 我已经尝试了以下SO帖子中的所有内容,但无济于事...

[ Python pip install module is not found. [ 找不到Python pip安装模块。 How to link python to pip location? 如何将python链接到pip位置?

The sys.path seems to point to the correct locations: sys.path似乎指向正确的位置:

>>> import sys
>>> type(sys.path)
<class 'list'>
>>> for path in sys.path:
...     print(path)
... 

/usr/lib/python35.zip
/usr/lib/python3.5
/usr/lib/python3.5/plat-arm-linux-gnueabihf
/usr/lib/python3.5/lib-dynload
/root/.local/lib/python3.5/site-packages
/usr/local/lib/python3.5/dist-packages
/usr/lib/python3/dist-packages

I'm at a loss here. 我在这里茫然。 Any suggestions you have would be great. 您的任何建议都会很棒。 Thank you. 谢谢。

UPDATE 更新

FWIW, this happened only after I did my usual: FWIW,这只有在我照常执行后才发生:

sudo apt-get update 
sudo apt-get upgrade 

Which yields to the following from uname: 从uname得出以下结果:

Linux raspberrypi 4.19.42-v7+ #1219 SMP Tue May 14 21:20:58 BST 2019 armv7l GNU/Linux Linux raspberrypi 4.19.42-v7 +#1219 SMP Tue May 14 21:20:58 BST 2019 armv7l GNU / Linux

Modules, or at least the ones I was importing, worked fine before this. 在此之前,模块或至少我要导入的模块可以正常工作。

Could it be that the pip command installs python2 packages? 是pip命令安装python2软件包吗? On my system for example I use pip for python 2 and pip3 for python3 packages. 例如,在我的系统上,我将pip用于python 2,将pip3用于python3软件包。

实际上,我无法使用python 3.x加载的模块可以在同一台机器上的python 2.x安装中识别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM