2009-09-19 109 views
125

我很难设置python包。从SetupTools EasyInstall应该可以帮助,但他们没有Python 2.6的可执行文件。如何在Windows上安装Python软件包?

例如,要安装Mechanize,我只是应该根据INSTALL.txt将Mechanize文件夹放在C:\ Python24 \ Lib \ site-packages中,但是运行测试不起作用。有人可以帮助解释这一点吗?谢谢!

+4

截至2014年3月,[所有平台上的Python 3.4都包含pip软件包管理器,包括Windows](https://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-453 )。所以确保你运行Python 3.4可能是一个不错的选择。 – 2014-06-03 07:01:40

+0

安装python 2.7.10或3.4以上版本,其中默认使用pip。然后使用python -m pip在cmd中安装Django等等 – userRaj 2015-11-30 08:20:16

回答

147

accepted answer已过时。首先,pip优于easy_install,(Why use pip over easy_install?)。然后按照这些步骤在Windows上安装pip,这很容易。

  1. 安装setuptools

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

    curl https://bootstrap.pypa.io/get-pip.py | python 
    
  3. 您可以选择的路径添加到您的环境,使您可以使用pip任何地方。它有点像C:\Python33\Scripts

+7

,这是唯一为我工作的人。 我的环境 - Python 3.3.1,Windows 7 64bit,x64 PC。如果可能的话,请注意这一点,为PPL节省很多麻烦。 – 2013-05-10 01:54:46

+7

上面的工作对我来说,但第二次与https发出警告关于ssl证书过期。必须在卷曲命令行上使用--insecure – Anton 2013-06-24 13:37:29

+1

1st答案仍然有效,但PIP优于IMO – 2013-10-08 13:46:23

21

您不需要setuptools的可执行文件。 您也可以下载源代码,解压缩,运行到下载目录,并运行在命令提示符下

+2

感谢您的回应!我在哪里解开它并在哪里运行该命令? – echoblaze 2009-09-19 21:07:43

+3

如果您下载了tar文件,只需使用WinRAR等程序将其解压缩即可。完成之后,打开命令提示符并导航到解压缩的文件夹(如果您看到'setup.py'文件,您将知道自己处于正确的位置)。从那里你可以运行'python setup.py install',它会为你安装它。 – 2009-09-19 21:27:46

52

Thispython setup.py install是如何得到easy_install窗户上一个很好的教程。简短的回答:将C:\Python26\Scripts(或者你安装的任何python)添加到你的PATH中。

+19

+1嘿感谢链接到我的文章。 – 2009-09-19 23:35:25

+0

步骤1 - 将python识别为命令 步骤2 - 运行setup.py文件 – 2011-05-31 20:49:36

+1

此答案已过时。请改变它。所有建议中的 – MeV 2015-11-18 12:49:54

0

您也可以下载并运行ez_setup.py,但SetupTools文档不再提示这一点。就在2周前,我工作得很好。

11

正如我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.


所以做正确的事就是安装点子。然而,如果你不能被打扰,Christoph Gohlke为所有Windows平台提供流行的Python软件包的二进制代码http://www.lfd.uci.edu/~gohlke/pythonlibs/

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

3

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

  • 首先,您需要将python安装添加到您的PATH变量中。 This应该有所帮助。
  • 您需要下载试图安装的zip格式的软件包并将其解压缩。如果它是一些奇怪的zip格式使用7Zip并且它应该被提取。
  • 导航到使用安装程序解压缩的目录。使用Windows PowerShell(使用链接,如果你有问题)
  • 运行命令python setup.py install

这为我工作的时候没有别的作出任何意义PY。我使用Python 2.7,但是文档表明这同样适用于Python 3.x。

66

更新版本的Python for Windows附带pip程序包管理器。 (source)

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

用它来安装软件包:

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

所以你的情况这会是:

pip.exe install mechanize 
+10

+1,因为这明确说在哪里键入“pip install ”大多数其他指南,在这里和其他地方,几乎认为我会知道这一点。 – 2014-07-24 08:07:32

+1

正如这是一个很好的答案!它当然假定python安装在c盘中。对于使用PowerShell的用户,如果您将python安装到其路径中有空格的目录中,请使用cd(“path”)更改目录。 – stt106 2015-09-23 20:59:43

+0

即使使用Python 2.7,这在Windows 10上也能很好地工作。感谢面向Windows的答案,这并没有让我的眼睛茫然。 – brichins 2016-06-03 15:50:55

8

与Python 2.7开始,PIP默认情况下包括在内。只需通过

python -m pip install [package-name] 
0
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 

下载你想要的包或只是把目录画中画可执行在你的系统路径。

0

正如Blauhirn在2.7点预装后提到的那样。如果它不适合你,它可能需要添加到路径。

但是,如果您运行Windows 10,则不必再打开终端来安装模块。打开Python也是一样。

您可以直接输入到搜索菜单pip install mechanize,选择命令,它会安装:

enter image description here

如果出现任何但是错了,它可能会关闭,然后才能读取错误,但它仍然是一个有用的快捷键。