1.1 环境搭建pipenv+python+pip+flask


一、环境搭建

 

F:\Workspaces\python\fisher>python -V
Python 3.7.0

F:\Workspaces\python\fisher>pip -V
pip 18.1 from f:\toos\anaconda3\lib\site-packages\pip (python 3.7)

F:\Workspaces\python\fisher>

1、安装pipenv ,版本号virtualenv-16.1.0

F:\Workspaces\python\fisher>pip install pipenv
Collecting pipenv
  Using cached https://files.pythonhosted.org/packages/90/06/0008f53835495fbbf6e31ced9119b8f517e1271bdefcf0d04aaa9f28dbf4/pipenv-2018.10.13-py3-none-any.whl
Requirement already satisfied: setuptools>=36.2.1 in f:\toos\anaconda3\lib\site-packages (from pipenv) (40.5.0)
Requirement already satisfied: certifi in f:\toos\anaconda3\lib\site-packages (from pipenv) (2018.8.24)
Collecting virtualenv (from pipenv)
  Using cached https://files.pythonhosted.org/packages/7c/17/9b7b6cddfd255388b58c61e25b091047f6814183e1d63741c8df8dcd65a2/virtualenv-16.1.0-py2.py3-none-any.whl
Collecting virtualenv-clone>=0.2.5 (from pipenv)
  Using cached https://files.pythonhosted.org/packages/16/9d/6419a4f0fe4350db7fdc01e9d22e949779b6f2d2650e4884aa8aededc5ae/virtualenv_clone-0.4.0-py2.py3-none-any.whl
Requirement already satisfied: pip>=9.0.1 in f:\toos\anaconda3\lib\site-packages (from pipenv) (18.1)
Installing collected packages: virtualenv, virtualenv-clone, pipenv
Successfully installed pipenv-2018.10.13 virtualenv-16.1.0 virtualenv-clone-0.4.0

 

 

2、到项目目录下利用pipenv 搭建项目虚拟环境

F:\Workspaces\python\fisher>pipenv install
Creating a virtualenv for this project…
Pipfile: F:\Workspaces\python\fisher\Pipfile
Using f:\toos\anaconda3\python.exe (3.7.0) to create virtualenv…
Already using interpreter f:\toos\anaconda3\python.exe
Using base prefix 'f:\\toos\\anaconda3'
New python executable in C:\Users\Administrator\.virtualenvs\fisher-JvHVc5uR\Scripts\python.exe
Installing setuptools, pip, wheel...
done.

Virtualenv location: C:\Users\Administrator\.virtualenvs\fisher-JvHVc5uR
Creating a Pipfile for this project…
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (a65489)!
Installing dependencies from Pipfile.lock (a65489)…
  ================================ 0/0 - 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

 

3、进入(运行)项目pipenv虚拟环境,此命令如果没有创建虚拟空间,会自己创建。

F:\Workspaces\python\fisher>pipenv shell
Launching subshell in virtual environment…
Microsoft Windows [版本 10.0.14393]
(c) 2016 Microsoft Corporation。保留所有权利。

(fisher-JvHVc5uR) F:\Workspaces\python\fisher>

 

4、检查是否进入本项目的虚拟环境

(fisher-JvHVc5uR) F:\Workspaces\python\fisher>pip list
Package    Version
---------- -------
pip        18.1
setuptools 40.5.0
wheel      0.32.2

(fisher-JvHVc5uR) F:\Workspaces\python\fisher>

 

 5、安装相关包:flask+ 

(fisher-JvHVc5uR) F:\Workspaces\python\fisher>pipenv install flask
Installing flask…
Collecting flask
  Downloading https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl (91kB)
Collecting itsdangerous>=0.24 (from flask)
  Downloading https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting click>=5.1 (from flask)
  Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)
Collecting Werkzeug>=0.14 (from flask)
  Downloading https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
Collecting Jinja2>=2.10 (from flask)
  Downloading https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl (126kB)
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10->flask)
  Downloading https://files.pythonhosted.org/packages/44/6e/41ac9266e3db762dfd9089f6b0d2298c84160f54ef2a7257c17b0e7ec2ec/MarkupSafe-1.1.0-cp37-cp37m-win_amd64.whl
Installing collected packages: itsdangerous, click, Werkzeug, MarkupSafe, Jinja2, flask
Successfully installed Jinja2-2.10 MarkupSafe-1.1.0 Werkzeug-0.14.1 click-7.0 flask-1.0.2 itsdangerous-1.1.0

Adding flask to Pipfile's [packages]…
Pipfile.lock (662286) out of date, updating to (a65489)…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (662286)!
Installing dependencies from Pipfile.lock (662286)…
  ================================ 6/6 - 00:00:02

(fisher-JvHVc5uR) F:\Workspaces\python\fisher>

 

 5.1 检查flask是否安装正常

(fisher-JvHVc5uR) F:\Workspaces\python\fisher>flask
Traceback (most recent call last):
  File "c:\users\administrator\.virtualenvs\fisher-jvhvc5ur\lib\site-packages\flask\cli.py", line 529, in list_commands
    rv.update(info.load_app().cli.list_commands(ctx))
  File "c:\users\administrator\.virtualenvs\fisher-jvhvc5ur\lib\site-packages\flask\cli.py", line 384, in load_app
    'Could not locate a Flask application. You did not provide '
flask.cli.NoAppException: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
Usage: flask [OPTIONS] COMMAND [ARGS]...

  A general utility script for Flask applications.

  Provides commands from Flask, extensions, and the application. Loads the
  application defined in the FLASK_APP environment variable, or from a
  wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
  will enable debug mode.

    > set FLASK_APP=hello.py
    > set FLASK_ENV=development
    > flask run

Options:
  --version  Show the flask version
  --help     Show this message and exit.

Commands:
  routes  Show the routes for the app.
  run     Runs a development server.
  shell   Runs a shell in the app context.

(fisher-JvHVc5uR) F:\Workspaces\python\fisher>

 

 5.2 卸载相关包

pipenv uninstall flask

 

 5.3 查看相关包的依赖关系

(fisher-JvHVc5uR) F:\Workspaces\python\fisher>pipenv graph
Flask==1.0.2(版本号)
  - click [required: >=5.1, installed: 7.0]()
  - itsdangerous [required: >=0.24, installed: 1.1.0](生成加密签名)
  - Jinja2 [required: >=2.10, installed: 2.10](模板渲染包)
    - MarkupSafe [required: >=0.23, installed: 1.1.0]
  - Werkzeug [required: >=0.14, installed: 0.14.1]


(fisher-JvHVc5uR) F:\Workspaces\python\fisher>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 








 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM