如何在 Windows 上安装 Python 包?

发布于 2024-08-05 01:24:55 字数 281 浏览 2 评论 0原文

我很难设置 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

り繁华旳梦境 2024-08-12 01:24:56

正如我在其他地方写的

Python 中的打包非常糟糕。根本原因是该语言在发布时没有包管理器。

幸运的是,有一个 Python 包管理器,名为 Pip 。 Pip 的灵感来自 Ruby 的 Gem,但缺少一些功能。讽刺的是,Pip 本身安装起来很复杂。在流行的 64 位 Windows 上安装需要从源代码构建和安装两个包。对于刚接触编程的人来说,这是一个很大的要求。


所以正确的做法是安装 pip。不过,如果您不介意的话,Christoph Gohlke 为所有 Windows 平台提供了流行 Python 包的二进制文件 http://www.lfd.uci.edu/~gohlke/pythonlibs/

事实上,构建一些 Python 包需要 C 编译器(例如 mingw32)和依赖项的库头。这在 Windows 上可能是一场噩梦,所以请记住 Christoph Gohlke 这个名字。

As I wrote elsewhere

Packaging in Python is dire. The root cause is that the language ships without a package manager.

Fortunately, there is one package manager for Python, called Pip. Pip is inspired by Ruby's Gem, but lacks some features. Ironically, Pip itself is complicated to install. Installation on the popular 64-bit Windows demands building and installing two packages from source. This is a big ask for anyone new to programming.


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.

哆啦不做梦 2024-08-12 01:24:56

我在 Windows 上安装软件包时遇到问题。找到了解决方案。它适用于 Windows7+。主要是任何带有 Windows Powershell 的东西都应该能够使其工作。 可以帮助您开始使用它。

  • 首先,您需要将 python 安装添加到 PATH 变量中。 应该有帮助。
  • 您需要下载要安装的 zip 格式的包并将其解压缩。如果它是一些奇怪的 zip 格式,请使用 7Zip 并且应该将其提取。
  • 使用 Windows Powershell 导航到使用 setup.py 提取的目录(如果遇到问题,请使用它的链接)
  • 运行命令 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.

  • Firstly, you'll need to add python installation to your PATH variable. This should help.
  • You need to download the package in zip format that you are trying to install and unzip it. If it is some odd zip format use 7Zip and it should be extracted.
  • Navigate to the directory extracted with setup.py using Windows Powershell (Use link for it if you have problems)
  • Run the command 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.

伏妖词 2024-08-12 01:24:56

通过命令提示符(Python目录)升级pip

D:\Python 3.7.2>python -m pip install --upgrade pip

现在您可以安装所需的模块

D:\Python 3.7.2>python -m pip install <<yourModuleName>>

Upgrade the pip via command prompt ( Python Directory )

D:\Python 3.7.2>python -m pip install --upgrade pip

Now you can install the required Module

D:\Python 3.7.2>python -m pip install <<yourModuleName>>
年华零落成诗 2024-08-12 01:24:56

pip 是 python 的包安装程序,先更新它,然后下载你需要的

python -m pip install --upgrade pip

然后:

python -m pip install <package_name>

pip is the package installer for python, update it first, then download what you need

python -m pip install --upgrade pip

Then:

python -m pip install <package_name>
秋千易 2024-08-12 01:24:56

您也可以只下载并运行 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.

莫相离 2024-08-12 01:24:56
PS D:\simcut>  C:\Python27\Scripts\pip.exe install networkx
Collecting networkx
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissingWarning: An HTTPS reques
t has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may caus
e the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer ve
rsion of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissi
ngwarning.
  SNIMissingWarning
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SS
LContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL con
nections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.
readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading networkx-1.11-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 664kB/s
Collecting decorator>=3.4.0 (from networkx)
  Downloading decorator-4.0.11-py2.py3-none-any.whl
Installing collected packages: decorator, networkx
Successfully installed decorator-4.0.11 networkx-1.11
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SSLContext object i
s not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade
to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplat
formwarning.
  InsecurePlatformWarning

或者只是将 pip 可执行文件的目录放在系统路径中。

PS D:\simcut>  C:\Python27\Scripts\pip.exe install networkx
Collecting networkx
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissingWarning: An HTTPS reques
t has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may caus
e the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer ve
rsion of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissi
ngwarning.
  SNIMissingWarning
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SS
LContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL con
nections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.
readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading networkx-1.11-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 664kB/s
Collecting decorator>=3.4.0 (from networkx)
  Downloading decorator-4.0.11-py2.py3-none-any.whl
Installing collected packages: decorator, networkx
Successfully installed decorator-4.0.11 networkx-1.11
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SSLContext object i
s not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade
to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplat
formwarning.
  InsecurePlatformWarning

Or just put the directory to your pip executable in your system path.

逆流 2024-08-12 01:24:56

正如 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:

enter image description here

If anything goes wrong however it may close before you can read the error but still it's a useful shortcut.

安穩 2024-08-12 01:24:55

接受的答案已过时。因此,首先, pip 优于 easy_install,(为什么使用 pip 而不是 easy_install?)。然后按照以下步骤在 Windows 上安装 pip ,非常简单。

  1. 安装setuptools

    curl https://bootstrap.pypa.io/ez_setup.py | Python
    
  2. 安装 pip:< /p>

    curl https://bootstrap.pypa.io/get-pip.py | Python
    
  3. (可选)您可以将路径添加到您的环境中,以便您可以在任何地方使用pip。它位于类似于 C:\Python33\Scripts 的位置。

The accepted answer is outdated. So first, pip is preferred over easy_install, (Why use pip over easy_install?). Then follow these steps to install pip on Windows, it's quite easy.

  1. Install setuptools:

    curl https://bootstrap.pypa.io/ez_setup.py | python
    
  2. Install pip:

    curl https://bootstrap.pypa.io/get-pip.py | python
    
  3. Optionally, you can add the path to your environment so that you can use pip anywhere. It's somewhere like C:\Python33\Scripts.

浪漫人生路 2024-08-12 01:24:55

Windows 版 Python 的较新版本附带了 pip 包管理器。 (来源)

如果您使用的是 Python 2 >=2.7.9 或 Python 3 >=3.4,则已安装 pip

使用它来安装软件包:

cd C:\Python\Scripts\
pip.exe install <package-name>

所以在您的情况下它是:

pip.exe install mechanize

Newer versions of Python for Windows come with the pip package manager. (source)

pip is already installed if you're using Python 2 >=2.7.9 or Python 3 >=3.4

Use that to install packages:

cd C:\Python\Scripts\
pip.exe install <package-name>

So in your case it'd be:

pip.exe install mechanize
一身骄傲 2024-08-12 01:24:55

This is a good tutorial on how to get easy_install on windows. The short answer: add C:\Python26\Scripts (or whatever python you have installed) to your PATH.

烟燃烟灭 2024-08-12 01:24:55

您不需要 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

雨落星ぅ辰 2024-08-12 01:24:55

从 Python 2.7 开始,默认包含 pip。只需通过以下方式下载您想要的包

python -m pip install [package-name]

Starting with Python 2.7, pip is included by default. Simply download your desired package via

python -m pip install [package-name]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文