如何在 Windows 上安装 Python 包?
我很难设置 python 包。 SetupTools 中的 EasyInstall 应该可以帮助解决这个问题,但他们没有适用于 Python 2.6 的可执行文件。
例如,要安装 Mechanize,我只是应该根据 INSTALL.txt 将 Mechanize 文件夹放在 C:\Python24\Lib\site-packages 中,但运行测试不起作用。有人可以帮助阐明这一点吗?谢谢!
I'm having a hard time setting up python packages. EasyInstall from SetupTools is supposed to help that, but they don't have an executable for Python 2.6.
For instance to install Mechanize, I'm just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
正如我在其他地方写的
所以正确的做法是安装 pip。不过,如果您不介意的话,Christoph Gohlke 为所有 Windows 平台提供了流行 Python 包的二进制文件 http://www.lfd.uci.edu/~gohlke/pythonlibs/
事实上,构建一些 Python 包需要 C 编译器(例如 mingw32)和依赖项的库头。这在 Windows 上可能是一场噩梦,所以请记住 Christoph Gohlke 这个名字。
As I wrote elsewhere
So the right thing to do is to install pip. However if you can't be bothered, Christoph Gohlke provides binaries for popular Python packages for all Windows platforms http://www.lfd.uci.edu/~gohlke/pythonlibs/
In fact, building some Python packages requires a C compiler (eg. mingw32) and library headers for the dependencies. This can be a nightmare on Windows, so remember the name Christoph Gohlke.
我在 Windows 上安装软件包时遇到问题。找到了解决方案。它适用于 Windows7+。主要是任何带有 Windows Powershell 的东西都应该能够使其工作。 这可以帮助您开始使用它。
python setup.py install
当没有其他任何意义时,该命令对我有用。我使用 Python 2.7,但文档表明同样适用于 Python 3.x。
I had problems in installing packages on Windows. Found the solution. It works in Windows7+. Mainly anything with Windows Powershell should be able to make it work. This can help you get started with it.
python setup.py install
That worked for me when nothing else was making any sense. I use Python 2.7 but the documentation suggests that same would work for Python 3.x also.
现在您可以安装所需的模块
Now you can install the required Module
pip 是 python 的包安装程序,先更新它,然后下载你需要的
然后:
pip is the package installer for python, update it first, then download what you need
Then:
您也可以只下载并运行 ez_setup.py,尽管 SetupTools 文档不再建议这样做。就在两周前,我还工作得很好。
You can also just download and run ez_setup.py, though the SetupTools documentation no longer suggests this. Worked fine for me as recently as 2 weeks ago.
或者只是将 pip 可执行文件的目录放在系统路径中。
Or just put the directory to your pip executable in your system path.
正如 Blauhirn 在预安装 2.7 pip 后提到的那样。如果它不适合您,可能需要将其添加到路径中。
但是,如果您运行 Windows 10,则不再需要打开终端来安装模块。打开 Python 也是如此。
您可以直接在搜索菜单中输入
pip install mechanize
,选择命令,它将安装:如果出现任何问题,它可能会在您读取错误之前关闭,但仍然存在这是一个有用的快捷方式。
As mentioned by Blauhirn after 2.7 pip is preinstalled. If it is not working for you it might need to be added to path.
However if you run Windows 10 you no longer have to open a terminal to install a module. The same goes for opening Python as well.
You can type directly into the search menu
pip install mechanize
, select command and it will install:If anything goes wrong however it may close before you can read the error but still it's a useful shortcut.
接受的答案已过时。因此,首先,
pip
优于easy_install
,(为什么使用 pip 而不是 easy_install?)。然后按照以下步骤在 Windows 上安装pip
,非常简单。安装
setuptools
:安装
pip
:< /p>(可选)您可以将路径添加到您的环境中,以便您可以在任何地方使用
pip
。它位于类似于C:\Python33\Scripts
的位置。The accepted answer is outdated. So first,
pip
is preferred overeasy_install
, (Why use pip over easy_install?). Then follow these steps to installpip
on Windows, it's quite easy.Install
setuptools
:Install
pip
:Optionally, you can add the path to your environment so that you can use
pip
anywhere. It's somewhere likeC:\Python33\Scripts
.Windows 版 Python 的较新版本附带了 pip 包管理器。 (来源)
使用它来安装软件包:
所以在您的情况下它是:
Newer versions of Python for Windows come with the pip package manager. (source)
Use that to install packages:
So in your case it'd be:
这是一个关于如何在 Windows 上获取
easy_install
的很好的教程。简短的答案:将C:\Python26\Scripts
(或您安装的任何 python)添加到您的 PATH 中。This is a good tutorial on how to get
easy_install
on windows. The short answer: addC:\Python26\Scripts
(or whatever python you have installed) to your PATH.您不需要 setuptools 的可执行文件。
您可以下载源代码,解压,遍历到下载的目录并在命令提示符下运行
python setup.py install
You don't need the executable for setuptools.
You can download the source code, unpack it, traverse to the downloaded directory and run
python setup.py install
in the command prompt从 Python 2.7 开始,默认包含 pip。只需通过以下方式下载您想要的包
Starting with Python 2.7, pip is included by default. Simply download your desired package via