首页 服务端python正文

Python3使用venv创建虚拟环境并安装依赖包(临时更换镜像源)

ixiaoye python 2020-03-29 1274 0 python

在学习使用flask过程中遇到一个问题,就是pip安装依赖包时出现这样那样不同的问题,在跳坑的过程学到了使用venv建立虚拟环境的方法,记录一下:

1、通过更换临时镜像源的方式下载venv:

virtualenv -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

2、在D盘test文件夹建立虚拟环境:D:\test>python -m venv .   (.是指当前文件夹,可以替换为其他路径)

3、激活当前虚拟环境  D:\test\Scripts>activate  #激活当前虚拟环境

D:\>cd test

D:\test>python -m venv .

D:\test>cd Scripts

D:\test\Scripts>activate


(test) D:\test\Scripts>pip3 install flask
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting flask
  Downloading https://mirrors.aliyun.com/pypi/packages/9b/93/628509b8d5dc749656a9641f4caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl (94kB)
    100% |████████████████████████████████| 102kB 4.7MB/s
Collecting Werkzeug>=0.15 (from flask)
  Downloading https://mirrors.aliyun.com/pypi/packages/ba/a5/d6f8a6e71f15364d35678a4ec8a0186f980b3bd2545f40ad51dd26a87fb1/Werkzeug-1.0.0-py2.py3-none-any.whl (298kB)
    100% |████████████████████████████████| 307kB 12.8MB/s
Collecting Jinja2>=2.10.1 (from flask)
  Downloading https://mirrors.aliyun.com/pypi/packages/27/24/4f35961e5c669e96f6559760042a55b9bcfcdb82b9bdb3c8753dbe042e35/Jinja2-2.11.1-py2.py3-none-any.whl (126kB)
    100% |████████████████████████████████| 133kB 10.3MB/s
Collecting click>=5.1 (from flask)
  Downloading https://mirrors.aliyun.com/pypi/packages/dd/c0/4d8f43a9b16e289f36478422031b8a63b54b6ac3b1ba605d602f10dd54d6/click-7.1.1-py2.py3-none-any.whl (82kB)
    100% |████████████████████████████████| 92kB 6.2MB/s
Collecting itsdangerous>=0.24 (from flask)
  Downloading https://mirrors.aliyun.com/pypi/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10.1->flask)
  Downloading https://mirrors.aliyun.com/pypi/packages/65/c6/2399700d236d1dd681af8aebff1725558cddfd6e43d7a5184a675f4711f5/MarkupSafe-1.1.1-cp37-cp37m-win_amd64.whl
Installing collected packages: Werkzeug, MarkupSafe, Jinja2, click, itsdangerous, flask
Successfully installed Jinja2-2.11.1 MarkupSafe-1.1.1 Werkzeug-1.0.0 click-7.1.1 flask-1.1.1 itsdangerous-1.1.0
You are using pip version 19.0.3, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

(test) D:\test\Scripts>pip3 install selenium
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting selenium
  Downloading https://mirrors.aliyun.com/pypi/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl (904kB)
    100% |████████████████████████████████| 911kB 11.4MB/s
Collecting urllib3 (from selenium)
  Downloading https://mirrors.aliyun.com/pypi/packages/e8/74/6e4f91745020f967d09332bb2b8b9b10090957334692eb88ea4afe91b77f/urllib3-1.25.8-py2.py3-none-any.whl (125kB)
    100% |████████████████████████████████| 133kB 17.1MB/s
Installing collected packages: urllib3, selenium
Successfully installed selenium-3.141.0 urllib3-1.25.8



评论