【发布时间】:2020-10-24 02:20:16
【问题描述】:
我正在尝试下载 openpyxl 2.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 来安装(也许这就是它不会在 python shell 中导入的原因?)但我得到了安装。
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
我去 Python 3.9.0 Shell 运行书中所说的导入命令,但收到此错误消息。
>>> import openpyxl
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
import openpyxl
ModuleNotFoundError: No module named 'openpyxl'
我想也许它没有安装正确?所以尝试重新安装 openpyxl 以查看它是否没有完全下载,然后我尝试了 pip3 freeze(并且显示了正确的 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
【问题讨论】:
-
如果您有多个 python 安装,可能会发生这种情况。调用
pip或pip3可能无法安装到您认为的 python 中...尝试使用python -m pip install openpyxl并将python替换为您用于启动 python 3.9.0 shell 的任何内容。
标签: python installation pip openpyxl