2017-01-30 145 views

回答

1

你應該將這個文件夾

C:\ Python27

,如果你已經安裝了Python爲所有用戶

0

你可以檢查Python的可執行文件位於用戶的主目錄。主目錄的位置通過使用os.path.expanduser()方法檢索。 Python解釋器的位置通過使用sys.executable()方法檢索。

如果Python解釋器安裝在用戶的主目錄中,以下函數返回True,否則返回False。它在Linux下工作,應該在macOS和Windows下工作(但我沒有測試這些)。

import sys 
import os 

def user_python(): 
    try: 
     return sys.executable.startswith(os.path.expanduser("~")) 
    except AttributeError: 
     return False 

需要的例外,因爲根據sys.executable()的文件,也可能在某些情況下返回None

相關問題