使用cookiecutter-flask时出现“地址已在使用中”错误

时间:2019-04-01 12:11:12

标签: python flask npm webpack cookiecutter-django

我在OS X 10.14.3上。我正在尝试使用外观漂亮的cookiecutter-flask项目。我已按照README.rst中的说明进行操作:

cookiecutter https://github.com/sloria/cookiecutter-flask.git
# I named my test ccflask, and used pipenv
cd ccflask
cp .env.example .env
pipenv install --dev
npm install
npm start

README说,此时,“您将看到一个漂亮的欢迎屏幕。”相反,它只是在ccflask/内部提供目录结构。

enter image description here

这似乎是因为烧瓶从未启动:

[FLASK] Loading .env environment variables...
[WEBPACK] Project is running at http://localhost:2992/
[WEBPACK] webpack output is served from http://localhost:2992/static/build/
[FLASK]  * Serving Flask app "autoapp.py" (lazy loading)
[FLASK]  * Environment: development
[FLASK]  * Debug mode: on
[FLASK] Traceback (most recent call last):
[FLASK]   File "/Users/nick/.local/share/virtualenvs/ccflask-bmCIsVly/bin/flask", line 10, in <module>
[FLASK]     sys.exit(main())
[…stack…]
[FLASK]     s.bind(get_sockaddr(hostname, port, address_family))
[FLASK] OSError: [Errno 48] Address already in use
[FLASK] npm ERR! code ELIFECYCLE
[FLASK] npm ERR! errno 1
[FLASK] npm ERR! ccflask@1.0.0 flask-server: `pipenv run flask run`
[FLASK] npm ERR! Exit status 1
[FLASK] npm ERR! 
[FLASK] npm ERR! Failed at the ccflask@1.0.0 flask-server script.
[FLASK] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我是npm和webpack的新手,所以我不太清楚问题是什么。当我搜索2992时,我在package.json中找到了它:

"webpack-dev-server": "NODE_ENV=debug webpack-dev-server --port 2992 --hot --inline",

以及webpack.config.js

const publicHost = debug ? 'http://localhost:2992' : '';

我不知道这看起来是否正确,但我认为是吗?控制台喷出的内容非常明确,即烧瓶应用程序和webpack开发服务器都从同一端口上的不同文件夹提供服务。我绝对不在2992上运行任何其他程序,因为一旦我杀死npm,localhost:2992就会停止响应Web请求。我也确定ps的输出。实际上,似乎npm start进程试图使用同一端口启动两个服务。

某些依赖关系可以改变吗?在npm install期间,我收到了以下警告:

npm WARN css-loader@1.0.1 requires a peer of webpack@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN less-loader@2.2.3 requires a peer of less@^2.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN url-loader@1.1.2 requires a peer of webpack@^3.0.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.

但是webpack中有一个node_modules目录,还有webpack-sourceswebpack-dev-*………所以我没主意。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

确实存在端口冲突,但不是与2992冲突。问题是我已经在端口5000上运行了另一个flask应用程序。一旦将其关闭,cookiecutter代码就会按预期工作。感谢GitHub上的kkremitzki帮助我解决了这个问题。