Python无法导入模块

时间:2019-02-11 08:13:54

标签: python-3.x module package pythonpath sys.path

我已经用pip3下载了python软件包bcrypt。但是,当我尝试在python3解释器中导入模块时,它说:

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

所以我想我只需要将软件包的目录添加到PYTHONPATH中即可。所以我确实运行了:

export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python3.7/site-packages/bcrypt

后跟一个:

source ~/.bashrc

然后,当我在python3解释器中打印sys.path时,它说:

>> import sys
>> print(sys.path)
['', '/Users/mauriciopaulusma', '/usr/local/lib/python3.7/site-packages/bcrypt', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyserial-3.4-py3.7.egg']

注意如何将目录“ /usr/local/lib/python3.7/site-packages/bcrypt”添加到sys.path中。但是,当我尝试在解释器中导入bcrypt时,它仍然无法导入bcrypt:

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

我还注意到,当我关闭终端,然后再次启动并运行另一个终端时,print(sys.path) 目录“ /usr/local/lib/python3.7/site-packages/bcrypt”已从sys.path中删除。

谁能告诉我如何解决此问题,以便python3可以导入bcrypt模块?

0 个答案:

没有答案