2009-09-19 69 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

如果出現任何但是錯了,它可能會關閉,然後才能讀取錯誤,但它仍然是一個有用的快捷鍵。