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/


猜你喜欢

转载自blog.51cto.com/12078224/2401112