2017-06-23 48 views
3

我試圖讓pip根據用戶的平臺從不同來源安裝numpy。我試圖通過使用「platform_system」環境標記來實現。有條件地使用pip安裝wheel文件

# requirements.txt 

# installing from a local wheel file 
/python35/wheels_repo/numpy-1.12.0.whl;platform_system == "Linux" 
# installing from PyPi 
numpy==1.12.0;platform_system == "Windows" 

它正常工作,當我在Linux上,但是當我在該文件的Windows PIP搜索 - 這甚至沒有在Windows中適當的文件路徑 - 即使它是由「platform_system保護」。

Requirement '/python35/wheels_repo/numpy-1.12.0.whl' looks like a filename, but the file does not exist 

然後安裝停止。

有沒有辦法讓pip找不到這個文件,或者至少是恢復安裝,如果找不到文件?

回答

0

我相信pip會一直檢查文件的存在。此檢查在檢查安裝要求(即,如果環境標記匹配)之前完成。

但是,您可以做的是讓pip在未找到文件的情況下繼續安裝。

/python35/wheels_repo/numpy-1.12.0.whl;platform_system == "Linux" 

到:

剛剛從改變你的要求

--find-links "file:///python35/wheels_repo/" numpy-1.12.0.whl;platform_system == "Linux" 

隨着--find鏈接點子,然後進入其中URI在稍後一點,只有評估的另一控制流程如果無效或未找到資源,則會導致打印警告。

編輯:

我剛剛意識到--find鏈接不會在requirements.txt單的要求工作。因爲你不是簡單地爲每個平臺安裝不同的軟件包,而是爲每個平臺安裝不同的軟件包,我建議將平臺特定的需求分成不同的文件(例如:requirements_Windows.txt和requirements_Linux。 txt)並在每個平臺上以不同的方式運行「pip install -r」。

在Windows上,你可以有即pip2pi,然後建立了一個本地包庫運行:

pip install --extra-index-url file://[path-to-your-local-package-repository]/simple -r requirements_Windows.txt