VS Python環境安裝第三方包 pip改國內源

2019.5.27

系統&軟件環境:Windows 10 Pro 1809, Visual Studio 2019 16.1.0, Python 3.7.2


網上有好多帖子說pip換國內源的辦法,現在驗證一下對於VS安裝的Python環境有沒有用。

打開Visual Studio,新建個Python應用程序項目。

圖片.png

圖一


我的打開後總是在右側就顯示了Python環境,這個界面也可以在下面的方法中打開:

在“解決方案資源管理器”中展開Python環境,顯示了這個項目實際的用的Python環境,在這個3.7的環境下右鍵,點擊紅框,就會到了上圖的界面。

圖片.png

圖二


圖一中這個框選擇“包(PyPI)”,等一會,下面就會出現已安裝的包。紅框下面的框,可以輸入想要安裝的包的名字。

圖片.png

圖三


比如輸入tensorflow,實際上執行的命令就是pip install tensorflow。如果臨時改用國內源,加上參數即可,比如--index https://pypi.mirrors.ustc.edu.cn/simple/ tensorflow,實際執行的就是pip install --index https://pypi.mirrors.ustc.edu.cn/simple/ tensorflow



顯然這樣又長又費勁,所以嘗試永久修改辦法。進入%HOMEPATH%目錄:

圖片.png

圖四


AK是我電腦的用戶名。新建pip目錄,新建文本文檔命名爲pip.ini,粘進去下面的內容:

[global]

timeout = 6000

index-url = https://pypi.tuna.tsinghua.edu.cn/simple

trusted-host = pypi.tuna.tsinghua.edu.cn


在VS中安裝setuptools包(實際上是升級了),在Visual Studio左下方“輸出”窗口出現如下信息(圖一)

----- 正在安裝“setuptools” -----
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting setuptools
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ec/51/f45cea425fd5cb0b0380f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.whl (575kB)
Installing collected packages: setuptools
  Found existing installation: setuptools 40.8.0
    Uninstalling setuptools-40.8.0:
      Successfully uninstalled setuptools-40.8.0
Successfully installed setuptools-41.0.1
----- 已成功安裝“setuptools” -----


說明成功修改爲國內源。



參考鏈接:

[1]vs2017 python環境安裝第三方包 - HPUGIS的博客 - CSDN博客

https://blog.csdn.net/weixin_40184249/article/details/80720015

(Powershell還是算了吧)

[2]PIP 更換國內安裝源 - Perry.Yuan - CSDN博客
https://blog.csdn.net/yuzaipiaofei/article/details/8089110


P.S.

圖片.png

上圖是我安裝VS的位置,所以:

E:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Lib\site-packages 安裝的第三方庫都放在了這裏,如NumPy。

E:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts  pip在這個目錄下。


pip國內的一些鏡像

  阿里雲                  http://mirrors.aliyun.com/pypi/simple/ 
  中國科技大學        https://pypi.mirrors.ustc.edu.cn/simple/ 
  豆瓣(douban)       http://pypi.douban.com/simple/ 
  清華大學               https://pypi.tuna.tsinghua.edu.cn/simple/ 
  中國科學技術大學  http://pypi.mirrors.ustc.edu.cn/simple/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章