我最初在 Python 3.5 中安装软件包时遇到问题,但我发现必须使用命令行而不是 IDLE shell 来安装 Python。
现在我已经成功安装了这个xlwt
包,我无法在 IDLE Python shell 中导入它来试用它。
这些片段如何相互关联?
我最初在 Python 3.5 中安装软件包时遇到问题,但我发现必须使用命令行而不是 IDLE shell 来安装 Python。
现在我已经成功安装了这个xlwt
包,我无法在 IDLE Python shell 中导入它来试用它。
这些片段如何相互关联?
根据您的环境,您可能已经安装了 Python 2(例如 Mac OSX 就是如此)。安装 Python 3 后,要访问它,您需要执行以下操作:
(pyenv)rook: nateford$ python3
Python 3.4.3 (default, Mar 10 2015, 14:53:35)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlwt
>>>
没有ImportError
发生,所以我们知道它有效。要确定您使用的是什么 python,您可以这样做:
(pyenv)rook: nateford$ which python
/Users/nateford/virtual_environments/pyenv/bin/python
(pyenv)rook: nateford$ which python3
/Users/nateford/virtual_environments/pyenv/bin/python3
(pyenv)rook: nateford$ python --version
Python 2.7.1
(pyenv)rook: nateford$ python3 --version
Python 3.4.3
(请注意,您的结果会有所不同,因为我使用的是在我的盒子上设置的虚拟环境。)
这个问题针对不同版本的 Python 解决了 IDLE:您应该能够根据您的版本访问它:
(pyenv)rook: nateford$ which idle
/opt/local/bin/idle
(pyenv)rook: nateford$ which idle3
(pyenv)rook: nateford$ which idle3.4
/opt/local/bin/idle3.4
(pyenv)rook: nateford$ which idle3.5
(pyenv)rook: nateford$
(再次注意,我使用的是 3.4 版本的 Python。)
同样,当您在命令行上安装包时,如果您是为 Python 版本 3 安装它们,则最好pip3
使用pip
. (从技术上讲,这里有一些微妙的地方,但对于命令行新手来说,这样想更容易。)