《Flask入门教程》第1章:安装Flask 报错,求解答


laoer:Watchlist laoer$ pipenv install flask
Installing flask...
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/cli.py", line 435, in install
    selective_upgrade=selective_upgrade,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/core.py", line 1971, in do_install
    pypi_mirror=pypi_mirror,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/core.py", line 1375, in pip_install
    package_name.split('--hash')[0].split('--trusted-host')[0]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/requirementslib/models/requirements.py", line 704, in from_line
    line, extras = _strip_extras(line)
TypeError: 'module' object is not callable
laoer:Watchlist laoer$ pipenv install flask
Installing flask...
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/cli.py", line 435, in install
    selective_upgrade=selective_upgrade,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/core.py", line 1971, in do_install
    pypi_mirror=pypi_mirror,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/core.py", line 1375, in pip_install
    package_name.split('--hash')[0].split('--trusted-host')[0]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/requirementslib/models/requirements.py", line 704, in from_line
    line, extras = _strip_extras(line)
TypeError: 'module' object is not callable

报错信息如上,请问该如何解决,网上搜了一圈还是没搞明白。预格式化文本

可能是pip版本出现问题,请尝试 pip install --upgrade pip==18.0

其实我感觉pip==10.0.1与pipenv兼容性最好的。

建议用全局Python安装pip==10.0.1python -m pip install pip==10.0.1,然后再pip install pipenv,最后pipenv install flask

或者直接试试把pipenv环境的pip切换为10.0.1:pipenv run python -m pip install pip==10.0.1

laoer:Documents laoer$ cd Watchlist
laoer:Watchlist laoer$ pipenv shell
Launching subshell in virtual environment…
bash-3.2$  . /Users/laoer/.local/share/virtualenvs/Watchlist-ox3trl5L/bin/activate
(Watchlist-ox3trl5L) bash-3.2$ 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 click>=5.1 (from flask)
  Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)
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 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/96/52/eef455862764cb6d6c136aa52c7f9fc4e7c1c644790a7107b1244a2b8a53/MarkupSafe-1.1.0-cp37-cp37m-macosx_10_6_intel.whl
Installing collected packages: click, itsdangerous, 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 (a65489) out of date, updating to (662286)...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
ons/3.7/lib/python3.7/site-packages/pipenv/utils.py", line 402, in resolve_deps
    req_dir=req_dir
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/utils.py", line 250, in actually_resolve_deps
    req = Requirement.from_line(dep)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/vendor/requirementslib/models/requirements.py", line 704, in from_line
    line, extras = _strip_extras(line)
TypeError: 'module' object is not callable

兄弟,按你给的方法重新试了下,还是报错

哥,切换了版本,还是不可以,郁闷了

重装大法好:wink:

重装全局Python,降级pip==10.0.1,重装pipenv,删除pipenv虚拟环境(pipenv --rm)再重新创建。

从最后报错信息来看,还是pipenv和pip版本的兼容问题的。建议保持pip==10.0.1,我一直用这个版本,升级到pip==18.0就会导致pipenv报错。

我也碰到了相同的错误。
pipenv install
Traceback (most recent call last):
File “c:\python37\lib\runpy.py”, line 193, in run_module_as_main
main”, mod_spec)
File “c:\python37\lib\runpy.py”, line 85, in run_code
exec(code, run_globals)
File "C:\python37\Scripts\pipenv.exe_main
.py", line 5, in
File "c:\python37\lib\site-packages\pipenv_init
.py", line 47, in
from .cli import cli
File “c:\python37\lib\site-packages\pipenv\cli_init_.py”, line 3, in
from .command import cli
File “c:\python37\lib\site-packages\pipenv\cli\command.py”, line 7, in
import crayons
File “c:\python37\lib\site-packages\pipenv\patched\crayons.py”, line 49, in
is_powershell = “powershell” in shellingham.detect_shell()[0]
File “c:\python37\lib\site-packages\pipenv\vendor\shellingham_init_.py”, line 22, in detect_shell
shell = get_shell(pid, max_depth=max_depth)
File “c:\python37\lib\site-packages\pipenv\vendor\shellingham\nt.py”, line 100, in get_shell
processes = dict(_iter_process())
File “c:\python37\lib\site-packages\pipenv\vendor\shellingham\nt.py”, line 78, in _iter_process
info = {‘executable’: str(pe.szExeFile.decode(‘utf-8’))}
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xcc in position 0: invalid continuation byte

我解决了,你的用户名称里是不是有中文。
我的是用户名称是英文,但是用户全名是中文。
打开计算机管理,本地用户和组,右键更改名称,再右键属性可以更改全名。