最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Mac本地用pipenv搭建Flask开发环境

Flask crifan 3116浏览 0评论

折腾:

【已解决】CentOS服务器中搭建Python的Flask的REST API

已经通过

【已解决】Python3中选择合适的虚拟环境工具

确定了用pipenv去搭建虚拟环境用于开发,所以先去本地Mac中折腾Flask的开发。

等弄好后,再去部署到远端CentOS服务器上。

先去本地Mac中安装pipenv:

【已解决】Mac本地安装Python3的pipenv虚拟环境

然后就是继续去:

搭建python3的Flask环境了。

mac python3 本地搭建 flask环境

在mac终端中如何切换到Python3 – 小谈博客

提到了,我关心的,如何切换为python3去开发

抽空试试:

第二期 · 阿里云Python+Flask环境搭建

第九期· 腾讯云部署Python3网站程序

提到的:

Termius

Mac上最简单配置python3开发环境 – 开发小记 – SegmentFault 思否

Mac环境下安装Flask – CSDN博客

mac python3   flask

在OSX上安装python3使用pip安装Flask – Bob-wei – 博客园

How to install python and Flask on Mac OS X

Mac环境下安装Flask – CSDN博客

Mac-Python flask环境搭建,以及python2个版本的安装。 – 简书

“所谓的虚拟环境是要在项目文件夹里创建文件夹,然后激活虚拟环境,再激活flask,再修改pycharm依赖的py环境。

意思就是多项目的时候,每一个项目创建对应的虚拟环境。

用pycharm超级方便,不用使用shell创建虚拟环境。打开关闭。”

抽空再去搞清楚,PyCharm中如何搭配本地pipenv创建的虚拟环境去开发Python

flask web开发环境搭建(Mac) – 君十一 – SegmentFault 思否

都是直接安装,但是这么知道安装的Flask是python2还是python3的?

欢迎使用 Flask — Flask 0.10.1 文档

Installation — Flask Documentation (0.12)

感觉还是看中文方便:

安装 — Flask 0.10.1 文档

Python 3 支持 — Flask 0.10.1 文档

但是刚发现:

Python 3 Support — Flask Documentation (0.12)

是最新的解释,还是要看的

install  python3 flask

python – How to install Flask on Python3 using pip? – Stack Overflow

安装python3版本的flask | XiaoTang’ Blog

算了,直接在pipenv的虚拟环境中去安装:

<code>➜  robotDemo pipenv shell
Spawning environment shell (/bin/zsh). Use 'exit' to leave.
. /Users/crifan/.local/share/virtualenvs/robotDemo-HXjMJQEQ/bin/activate
➜  robotDemo . /Users/crifan/.local/share/virtualenvs/robotDemo-HXjMJQEQ/bin/activate
➜  robotDemo pipenv install flask
Installing flask…
Collecting flask
  Downloading https://files.pythonhosted.org/packages/77/32/e3597cb19ffffe724ad4bf0beca4153419918e7fa4ba6a34b04ee4da3371/Flask-0.12.2-py2.py3-none-any.whl (83kB)
Collecting itsdangerous&gt;=0.21 (from flask)
  Downloading https://files.pythonhosted.org/packages/dc/b4/a60bcdba945c00f6d608d8975131ab3f25b22f2bcfe1dab221165194b2d4/itsdangerous-0.24.tar.gz (46kB)
Collecting click&gt;=2.0 (from flask)
  Downloading https://files.pythonhosted.org/packages/34/c1/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77/click-6.7-py2.py3-none-any.whl (71kB)
Collecting Werkzeug&gt;=0.7 (from flask)
  Downloading https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
Collecting Jinja2&gt;=2.4 (from flask)
  Downloading https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl (126kB)
Collecting MarkupSafe&gt;=0.23 (from Jinja2&gt;=2.4-&gt;flask)
  Downloading https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz
Building wheels for collected packages: itsdangerous, MarkupSafe
  Running setup.py bdist_wheel for itsdangerous: started
  Running setup.py bdist_wheel for itsdangerous: finished with status 'done'
  Stored in directory: /Users/crifan/Library/Caches/pip/wheels/2c/4a/61/5599631c1554768c6290b08c02c72d7317910374ca602ff1e5
  Running setup.py bdist_wheel for MarkupSafe: started
  Running setup.py bdist_wheel for MarkupSafe: finished with status 'done'
  Stored in directory: /Users/crifan/Library/Caches/pip/wheels/33/56/20/ebe49a5c612fffe1c5a632146b16596f9e64676768661e4e46
Successfully built itsdangerous MarkupSafe
Installing collected packages: itsdangerous, click, Werkzeug, MarkupSafe, Jinja2, flask
Successfully installed Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 click-6.7 flask-0.12.2 itsdangerous-0.24

Adding flask to Pipfile's [packages]…
Pipfile.lock (625834) out of date, updating to (011179)…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (011179)!
Installing dependencies from Pipfile.lock (011179)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 6/6 — 00:
</code>

然后看看安装的效果:

<code>➜  robotDemo pipenv graph
Flask==0.12.2
  - click [required: &gt;=2.0, installed: 6.7]
  - itsdangerous [required: &gt;=0.21, installed: 0.24]
  - Jinja2 [required: &gt;=2.4, installed: 2.10]
    - MarkupSafe [required: &gt;=0.23, installed: 1.0]
  - Werkzeug [required: &gt;=0.7, installed: 0.14.1]

➜  robotDemo cat Pipfile
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "*"

[dev-packages]

[requires]
python_version = "3.6"
➜  robotDemo cat Pipfile.lock
{
    "_meta": {
        "hash": {
            "sha256": "cbf8e638e8cd1a98e1008cd9f9ead22772a784d607fbc4e41b89de5b19011179"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.6"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.python.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "click": {
            "hashes": [
                "sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d",
                "sha256:f15516df478d5a56180fbf80e68f206010e6d160fc39fa508b65e035fd75130b"
            ],
            "version": "==6.7"
        },
        "flask": {
            "hashes": [
                "sha256:0749df235e3ff61ac108f69ac178c9770caeaccad2509cb762ce1f65570a8856",
                "sha256:49f44461237b69ecd901cc7ce66feea0319b9158743dd27a2899962ab214dac1"
            ],
            "index": "pypi",
            "version": "==0.12.2"
        },
        "itsdangerous": {
            "hashes": [
                "sha256:cbb3fcf8d3e33df861709ecaf89d9e6629cff0a217bc2848f1b41cd30d360519"
            ],
            "version": "==0.24"
        },
        "jinja2": {
            "hashes": [
                "sha256:74c935a1b8bb9a3947c50a54766a969d4846290e1e788ea44c1392163723c3bd",
                "sha256:f84be1bb0040caca4cea721fcbbbbd61f9be9464ca236387158b0feea01914a4"
            ],
            "version": "==2.10"
        },
        "markupsafe": {
            "hashes": [
                "sha256:a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665"
            ],
            "version": "==1.0"
        },
        "werkzeug": {
            "hashes": [
                "sha256:c3fd7a7d41976d9f44db327260e263132466836cef6f91512889ed60ad26557c",
                "sha256:d5da73735293558eb1651ee2fddc4d0dedcfa06538b8813a2e20011583c9e49b"
            ],
            "version": "==0.14.1"
        }
    },
    "develop": {}
}
➜  robotDemo
</code>

突然,看到

给有经验程序员的前言 — Flask 0.10.1 文档

提到,建议还是用Python2

“我们强烈建议在开发时使用 Python 2.6 和 2.7 ,并激活 Python 3 警告。如果你计划在近期升级到 Python 3 ,我们强烈推荐你阅读 如何编写向后兼容的 Python 代码 。”

所以再去看看:

flask python2 python3

Is it best to use Python 2 or 3 for Flask? – Quora

“Now I wanna share my personal experience. Flask 0.10 nicely supports Python 3.4. I have already developed two projects on it. Also this is the time of Python3 as Python2 will be out of support after 2020. So, I’ll recommend to use Python3.”

那就用python3吧。

pip – install flask for python2 when python 3 is default – Stack Overflow

Python 2 or 3 best for Flask?:Python

也是建议用Python3了。

然后写个demo的py文件,尝试去放到PyCharm中运行试试

【已解决】PyCharm中如何调试pipenv的虚拟环境中的python3的文件

【总结】

至此,算是完成了,Mac本地搭建的python的pipenv的虚拟环境,且在PyCharm中能正常调试了。

转载请注明:在路上 » 【已解决】Mac本地用pipenv搭建Flask开发环境

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.181 seconds, using 22.17MB memory