python安裝numpy科學計算模塊


解決兩個問題:

(1)Import Error: No module named numpy

(2)Python version 2.7 required, which was not found in the registry

(1)這種錯誤是因為沒有安裝numpy科學計算庫,因此需要安裝此模塊。

  1. 首先下載正確的exe安裝文件:numpy-MKL-1.8.0.win-amd64-py2.7.exe。

  2. 接着我們雙加打開安裝文件,點擊運行按鈕

  3. 安裝過程很簡單,點擊下一步

  4. 在第一步,如果你看到自己的python的版本號和安裝路徑,說明你的numpy下載的版本是正確的,點擊下一步

  5. 一直點擊下一步即可完成安裝

  6. 打開python,我們輸入import numpy,如果沒有提示錯誤信息,就說明我們安裝完成

注意:在安裝的過程中,可能會出現:

Python version 2.7 required, which was not found in the registry

這是因為python安裝時沒有寫入到注冊表中:

解決方法為:

寫一個如下腳本,可以命名為:PythonRegister.py:

 1 # script to register Python 2.0 or later for use with win32all  
 2 # and other extensions that require Python registry settings  
 3 #  
 4 # written by Joakim Loew for Secret Labs AB / PythonWare  
 5 #  
 6 # source:  
 7 # http://www.pythonware.com/products/works/articles/regpy20.htm  
 8 #  
 9 # modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html  
10    
11 import sys  
12    
13 from _winreg import *  
14    
15 # tweak as necessary  
16 version = sys.version[:3]  
17 installpath = sys.prefix  
18    
19 regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)  
20 installkey = "InstallPath"  
21 pythonkey = "PythonPath"  
22 pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (  
23     installpath, installpath, installpath  
24 )  
25    
26 def RegisterPy():  
27     try:  
28         reg = OpenKey(HKEY_CURRENT_USER, regpath)  
29     except EnvironmentError as e:  
30         try:  
31             reg = CreateKey(HKEY_CURRENT_USER, regpath)  
32             SetValue(reg, installkey, REG_SZ, installpath)  
33             SetValue(reg, pythonkey, REG_SZ, pythonpath)  
34             CloseKey(reg)  
35         except:  
36             print "*** Unable to register!"  
37             return  
38         print "--- Python", version, "is now registered!"  
39         return  
40     if (QueryValue(reg, installkey) == installpath and  
41         QueryValue(reg, pythonkey) == pythonpath):  
42         CloseKey(reg)  
43         print "=== Python", version, "is already registered!"  
44         return  
45     CloseKey(reg)  
46     print "*** Unable to register!"  
47     print "*** You probably have another Python installation!"  
48    
49 if __name__ == "__main__":  
50     RegisterPy()  

然后在CMD中執行:

啟動命令切換到PythonRegister.py文件目錄下執行

重新安裝PIL,錯誤解決,安裝成功。

此時就可以重新安裝numpy庫。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM