實驗室的服務器木有連接外網,無法使用pip進行安裝,真正意義上的離線安裝需要很多安裝依賴包,下載起來很麻煩,而且版本號還不一定對。
另一種方法是利用源代碼編譯安裝,那樣也需要安裝依賴包,比較麻煩。
經過折騰,我采用的是利用一台可以上外網的PC搭建代理服務器,利用代理服務器進行PIP安裝。
搭建代理服務器:
代理服務我使用的是py2寫的腳本。我的py2環境基於Anaconda2,很多依賴包已經安裝好,Anaconda的安裝見:(Ubuntu16.04 Liunx下同時安裝Anaconda2與Anaconda3)
-
將python環境設為py2 ,pip 安裝以下包:Twisted PyOpenSSL,PyCrypto ZopeInterface
- 安裝好之后,腳本如下:
-
from twisted.web import proxy, http from twisted.internet import reactor from twisted.python import log import sys log.startLogging(sys.stdout) class ProxyFactory(http.HTTPFactory): protocol = proxy.Proxy reactor.listenTCP(808, ProxyFactory()) reactor.run()
運行腳本
在服務器上運行:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --proxy=http://x.x.x.x:808 -U --pre tensorflow-gpu
x.x.x.x是你能上外網pc的ip
keras 安裝見http://keras-cn.readthedocs.io/en/latest/for_beginners/keras_linux/,在安裝命令前加上
-i http://pypi.douban.com/simple --proxy=http://x.x.x.x:808 即可。
參考:
https://wiki.python.org/moin/Twisted-Examples
http://www.cnblogs.com/llhf/p/python-proxy-for-pip.html
http://keras-cn.readthedocs.io/en/latest/for_beginners/keras_linux/