ModuleNotFoundError:没有名为“openpyxl”的模块

2024-05-29 05:28:18 发布

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

我正试图下载OpenPYXL2.6.2,因为这是this book用于Excel自动化示例的版本。我目前在Ubuntu中的python版本是3.8.5,不过我已经在桌面上下载了python 3.9.0,我目前的python Shell是3.9.0

首先,我尝试使用书中的代码,但出现以下错误:

gcab@DESKTOP:~$ pip install --user -U openpyxl==2.6.2
Command 'pip' not found, but there are 18 similar ones.

我发现我需要使用pip3而不是pip来安装(也许这就是为什么它不会导入到pythonshell中?)

gcab@DESKTOP:~$ pip3 install --user -U openpyxl==2.6.2
Collecting openpyxl==2.6.2
  Downloading openpyxl-2.6.2.tar.gz (173 kB)
     |████████████████████████████████| 173 kB 507 kB/s
Collecting et_xmlfile
  Downloading et_xmlfile-1.0.1.tar.gz (8.4 kB)
Collecting jdcal
  Downloading jdcal-1.4.1-py2.py3-none-any.whl (9.5 kB)
Building wheels for collected packages: openpyxl, et-xmlfile
  Building wheel for openpyxl (setup.py) ... done
  Created wheel for openpyxl: filename=openpyxl-2.6.2-py2.py3-none-any.whl size=245216 sha256=77b53f3225fc950489bccb7f8a0684af70240ca7e9bbf1b2df85f6383a1a596e
  Stored in directory: /home/gcab/.cache/pip/wheels/97/27/98/11bd6a09ec9aa1034ea765af5c2a9d71589c1f012f86fc2481
  Building wheel for et-xmlfile (setup.py) ... done
  Created wheel for et-xmlfile: filename=et_xmlfile-1.0.1-py3-none-any.whl size=8915 sha256=587d3cf5b7362f3930e45c912b901dd236abfdbc379bbdc35880bd8120bfbda5
  Stored in directory: /home/gcab/.cache/pip/wheels/6e/df/38/abda47b884e3e25f9f9b6430e5ce44c47670758a50c0c51759
Successfully built openpyxl et-xmlfile
Installing collected packages: et-xmlfile, jdcal, openpyxl
Successfully installed et-xmlfile-1.0.1 jdcal-1.4.1 openpyxl-2.6.2

我转到Python3.9.0shell,按照书中所说的那样运行import命令,但是得到了这个错误消息

>>> import openpyxl
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    import openpyxl
ModuleNotFoundError: No module named 'openpyxl'

我想也许它安装不正确?因此,我尝试重新安装openpyxl,看看它是否还没有完全下载,然后我尝试了pip3冻结(正确的openpyxl版本出现了)。有什么建议吗

gcab@DESKTOP:~$ pip3 install --user -U openpyxl==2.6.2
Requirement already up-to-date: openpyxl==2.6.2 in ./.local/lib/python3.8/site-packages (2.6.2)
Requirement already satisfied, skipping upgrade: jdcal in ./.local/lib/python3.8/site-packages (from openpyxl==2.6.2) (1.4.1)
Requirement already satisfied, skipping upgrade: et-xmlfile in ./.local/lib/python3.8/site-packages (from openpyxl==2.6.2) (1.0.1)
gcab@DESKTOP:~$ pip3 freeze
openpyxl==2.6.2

Tags: installpipin版本forkbpackagespip3

热门问题