环境配置与安装

2020-06-01  本文已影响0人  royluck
python安装

Python 3.7.7(我这里安装的是3.7.7版本,为了兼容pycharm2018.3.4)


pycharm破解安装

安装pipenv

虚拟环境的作用:隔离项目环境

pip list
pip install pipenv
pipenv shell // 进入虚拟环境(注意这个操作,会在你当前执行的目录文件地址创建虚拟环境,所以如果你是拉的项目,记得进入到pipfile文件的目录之下执行该操作)
pipenv install // 安装pipfile文件的依赖
pipenv install flask // 安装指定依赖(插件)
exit // 退出虚拟环境
pipenv graph  // 查看安装包依赖关系(如果新拉下来的项目,没执行pipenv install,如果你执行该操作,输出为空)
pipenv --venv // 查找虚拟环境地址
pipenv uninstall werkzeug
pipenv install werkzeug==0.16.1

拉取新项目的操作流程:

(参考下面“拉取慕课网项目问题”)

step4:执行pipenv install安装依赖包
注意:有时候拉下来的代码,会存在版本兼容问题,需要降低相关包的版本如:
ImportError: cannot import name 'url_encode' from 'werkzeug'



项目结构:

MVC

app---
  --form  // 扶着传参校验
  --libs
  --models
  --spider
  --static
  --templates
  --view_models
  --web
go.py // 入口文件

Python项目的组织结构:
__file__ 值是上述打印的path: __path__
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "==1.0"
flask-sqlalchemy = "==2.3.2"
flask-wtf = "==0.14.2"
cymysql = "==0.9.1"
flask-cors = "==2.1.0"
flask-httpauth = "==2.7.0"
requests = "==2.18.4"

[dev-packages]

[requires]
python_version = "3.6"


@app.route('/v1/user/get')
def get_user():
    return 'get user'
Traceback (most recent call last):                                          
  File "c:\program files\python37\lib\site-packages\pipenv\project.py", line
 567, in _parse_pipfile                                                     
    return tomlkit.parse(contents)                                          
  File "c:\program files\python37\lib\site-packages\pipenv\vendor\tomlkit\ap
i.py", line 49, in parse                                                    
    return Parser(string).parse()                                           
  File "c:\program files\python37\lib\site-packages\pipenv\vendor\tomlkit\pa
rser.py", line 146, in parse    
...                                            

解决:mac电脑下pipenv install 报错

Warning: Python 3.6 was not found on your system…
Neither 'pyenv' nor 'asdf' could be found to install Python.
You can specify specific versions of Python with:
$ pipenv --python path\to\python

将pipfile python版本改成3.7 或者直接删掉

[requires]
python_version = "3.7"
raise Exception("Install 'email_validator' for email validation support.")
Exception: Install 'email_validator' for email validation support.

解决:pipenv install email_validator


ginger源码
链接:https://pan.baidu.com/s/1IKduqG35TLsrAP3fnmT39Q

上一篇 下一篇

猜你喜欢

热点阅读