简体   繁体   中英

Installed Python Modules Can't Be Imported

I have multiple indications that my python modules are installed but several cause 'No module named..' exceptions. 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. Others are just fine.

I've tried everything in the following SO post, to no avail...

[ Python pip install module is not found. How to link python to pip location?

The sys.path seems to point to the correct locations:

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

sudo apt-get update 
sudo apt-get upgrade 

Which yields to the following from uname:

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? On my system for example I use pip for python 2 and pip3 for python3 packages.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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