1. 程式人生 > >python 2.7.5找不到pip的問題

python 2.7.5找不到pip的問題

    不知是否是python版本太低還是什麼原因,python目錄下沒有Scripts這個資料夾,很多指令都用不了。包括pip和easy_install。

    網上的教程是直接前往官網下載 pip下載連結

    下載解壓後用命令列會發現,缺少另一個工具setuptools,這個是我python2.7.5遇到過的,其他版本不知有沒有遇到。

     解壓後,輸入指令 python setup.py install回車

    會在python目錄下產生Script資料夾。裡面集成了很多.py的 檔案。

    這時候再去剛剛下載的pip檔案 夾,輸入python setup.py install回車

    就可以安裝python pip

    當然需要把python下的Scripts資料夾加入環境變數。

這裡分享一個python註冊到註冊列表的一個py程式碼指令

import sys


from _winreg import *

# tweak as necessary 
version = sys.version[:3] 
installpath = sys.prefix  
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
installpath, installpath, installpath
)

def RegisterPy():
    print "begin RegisterPy "
    try:
        print "open key : %s"%regpath
        reg = OpenKey(HKEY_CURRENT_USER, regpath)
    except EnvironmentError as e:    
        try:           
            reg = CreateKey(HKEY_CURRENT_USER, regpath) 
            SetValue(reg, installkey, REG_SZ, installpath) 
            SetValue(reg, pythonkey, REG_SZ, pythonpath)
            CloseKey(reg) 
        except: 
            print "*** EXCEPT: Unable to register!" 
            return             
        
        print "--- Python", version, "is now registered!" 
        return

   
    if (QueryValue(reg, installkey) == installpath and 
        QueryValue(reg, pythonkey) == pythonpath): 
            CloseKey(reg) 
            print "=== Python", version, "is already registered!" 
            return CloseKey(reg) 

    print "*** ERROR:Unable to register!" 
    print "*** REASON:You probably have another Python installation!"

def UnRegisterPy():
    #print "begin UnRegisterPy "
    try:
        print "open HKEY_CURRENT_USER key=%s"%(regpath)
        reg = OpenKey(HKEY_CURRENT_USER, regpath)
        #reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
    except EnvironmentError:  
        print "*** Python not registered?!"
        return
    try:
       DeleteKey(reg, installkey)
       DeleteKey(reg, pythonkey)
       DeleteKey(HKEY_LOCAL_MACHINE, regpath)
    except:
       print "*** Unable to un-register!"
    else:
       print "--- Python", version, "is no longer registered!"            

if __name__ == "__main__":  
    RegisterPy()

參考大神部落格:https://blog.csdn.net/nomey_mr/article/details/55095984和https://blog.csdn.net/DongGeGe214/article/details/52199439