I am trying to create a npm run script that can start react app and then activate python virtual env to run flask server.
我正在尝试创建一个NPM运行脚本,可以启动反应应用程序,然后激活python虚拟环境来运行flASK服务器。
scripts in package.json:
Package.json中的脚本:
{
"scripts": {
"start": "react-scripts start",
"both": "concurrently \"react-scripts start\" \"cd ../backend && "env/scripts/activate\" && py src/app.py\"",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
}
above I am using concurrently
. But executing the both
script run react and give following error:
以上是我同时使用的。但是执行这两个脚本运行会有反应,并给出以下错误:
[1] 'env' is not recognized as an internal or external command,
[1] operable program or batch file.
[1] cd ../backend && env/scripts/activate && py src/app.py exited with code 1
[0] i 「wds」: Project is running at http://192.168.137.1/
[0] i 「wds」: webpack output is served from
[0] i 「wds」: Content not from webpack is served from D:\Work\movielust\frontend\public
[0] i 「wds」: 404s will fallback to /
[0] Starting the development server...
My dir structure is:
我的目录结构是:
main
|___frontend
| |___package.json
|___backend
| |___env
| |___src
| |___app.py
is there any workaround for this or this not really possible or is threre any other way to achieve running both react and flask in one go?
有没有解决这个或这个不太可能的解决办法,或者有没有其他方法可以同时运行反应和烧瓶?
更多回答
How did you create your virtual environment? Via virtualenv?
您是如何创建您的虚拟环境的?通过Virtualenv?
@Virtuoz yes with virtualenv
@VirtuOz可以使用Virtualenv
Did you try . env\scripts\activate
?
你试过了吗。环境\脚本\激活?
just tried, it gave '.env' is not recognized as an internal or external command,
@Virtuoz
刚刚尝试过,它给出‘.env’未被识别为内部或外部命令@VirtuOz
优秀答案推荐
- run your virtual environment
- don't try to change path or activate virtualenv from within the scripts in package.json
"scripts":
"flask-dev": "pip install -r requirements.txt && python -m flask --app api/index run -p 5328 --reload",
"next-dev": "next dev",
"dev": "concurrently \"pnpm run next-dev\" \"pnpm run flask-dev\"",
then run npm run dev which will pick up the environment and packages from it...
然后运行NPM run dev,它将从其中获取环境和包……
更多回答
我是一名优秀的程序员,十分优秀!