未找到Pip成功安装的模块:ImportError:没有名为xlwt的模块

2024-10-02 00:27:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我的操作系统:赢10

已安装:

  • python 2.7(命令为python
  • python 3.9.5(命令为python3
  • pip,pip3(两个都是python3,似乎都是)

pip命令:

c:\>pip3 config list -v
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'c:\users\luelue\appdata\local\programs\python\python39\pip.ini'

c:\>pip config list -v
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'c:\users\luelue\appdata\local\programs\python\python39\pip.ini'

我通过pip安装了xlwt,我可以看到它已安装:

c:\>pip install xlwt
Requirement already satisfied: xlwt in c:\users\luelue\appdata\local\programs\python\python39\lib\site-packages\xlwt-1.3.0-py3.9.egg (1.3.0)

enter image description here

然而,当我尝试导入它时,得到了错误:No module named xlwt

c:\>python
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlwt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named xlwt
>>> exit()

此外,我成功地使用了pip3 install xlwt,但运行python3 ... import xlwt失败。完整日志:

C:\files\dong_tai_pai_fang_ji_suan\python_code>pip3 install xlwt
Requirement already satisfied: xlwt in c:\users\luelue\appdata\local\programs\python\python39\lib\site-packages\xlwt-1.3.0-py3.9.egg (1.3.0)

C:\files\dong_tai_pai_fang_ji_suan\python_code>python3
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlwt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'xlwt'
>>>

如何解决这个问题

我应该为python/pip配置windows路径还是什么

谢谢

编辑:

也许我安装了多个python3: enter image description here


Tags: pipforpip3sitewillusersinipython3
3条回答

也许我安装了多个python3

执行python3 -m pip install xlwt,这总是为python3安装(当您在终端中执行python3时启动python),那么应该可以在python3中导入已安装的模块。如果你想知道更多关于这方面的信息,请阅读Installing Python Modules in docs

好的,我终于找到了根本原因

我的电脑中有两个python版本:

  1. 版本3.9,这是我自己安装的
  2. 版本2.7,由electron vue自动安装

我相信这两个版本的配置之间存在一些冲突。(例如执行路径、pip路径等)导致pip install工作不正常

解决方案非常简单:卸载所有python版本并重新安装3.7,一切都很顺利

在python控制台中,您的python版本是2.7。 更改为python 3.9版本

相关问题 更多 >

    热门问题