python : Python egg cache directory 異常處理

G8bao7發表於2016-12-15
轉載: 

異常內容


用php呼叫python指令碼時報出這個異常,從提示看,沒有許可權訪問 $PYTHON_EGG_CACHE 

點選(此處)摺疊或開啟

  1. pkg_resources.ExtractionError: Can't extract file(s) to egg cache
  2. The following error occurred while trying to extract file(s) to the Python egg
  3. cache:
  4. [Errno 13] Permission denied: '/root/.cache'
  5. The Python egg cache directory is currently set to:
  6. /root/.cache/Python-Eggs
  7. Perhaps your account does not have write access to this directory? You can
  8. change the cache directory by setting the PYTHON_EGG_CACHE environment
  9. variable to point to an accessible directory.

解決辦法:

程式碼裡設定 PYTHON_EGG_CACHE,

點選(此處)摺疊或開啟

  1. import os
  2. os.environ['PYTHON_EGG_CACHE'] = '/tmp'
在import其他包之前

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26250550/viewspace-2130690/,如需轉載,請註明出處,否則將追究法律責任。

相關文章