如何让 Python3 找到已安装的模块?

How to get Python3 to find installed module?

我正在尝试在 CentOS centos-release-7-6.1810.2 上安装 xlsxwriter。el7.centos。x86_64

当我安装时 xlsxwriter:

703404669@bioitutil2:~$ sudo pip3 install xlsxwriter
Requirement already satisfied: xlsxwriter in /usr/lib64/python3.4/site-packages (1.2.6)

当我尝试加载模块时,我收到一条矛盾的消息:

703404669@bioitutil2:~$ python3
Python 3.6.8 (default, Aug  7 2019, 17:28:10) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlsxwriter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'xlsxwriter'

我也试过 pip3.6,但出现更多错误:

703404669@bioitutil2:~$ sudo pip3.6 install xlsxwriter
Traceback (most recent call last):
  File "/bin/pip3.6", line 16, in <module>
    sys.exit(main())
TypeError: 'module' object is not callable

如何让 python3 找到 xlsxwriter

pip3 install xlsxwriter

给你

Requirement already satisfied: xlsxwriter in /usr/lib64/python3.4/site-packages (1.2.6)

所以它是为 python3.4 安装的,但是 python3 调用 Python 3.6.8,所以两个不同的 python 版本有它们单独的 site-package 目录。

您可以通过python3 -m pip install来避免这个问题,这应该

  1. 确保您安装的是您打算使用的 python 版本
  2. 避免 'module' object is not callable 错误

备注

我不知道你怎么会有两个 python 版本,但可能值得检查一下你是否可以卸载其中一个,然后使用虚拟环境或类似环境来管理多个 python 系统上的版本