Reputation: 17
I'm trying to develop a SPA with PyCharm which uses venv as the virtual environment for my project.
I'm following this tutorial https://auth0.com/blog/using-python-flask-and-angular-to-build-modern-apps-part-1/ but the config is based on a linux system. I'm stuck on the part where I want to run a bootstrap script to run my flask app from the command line.
It seemed reasonable to put this into a PowerShell script, as I'm developing on Windows 10, but I'm unable to run this script from within venv.
The script itself just contains the following:
$env:FLASK_APP = "./src/main.py"
flask run -h 0.0.0.0
Now, within venv I can only launch a PowerShell terminal. I can't actually run this script from within venv directly. If I navigate to the venv folder from within PowerShell my script will be executable but it's obviously not working as flask is only available within venv.
So, please can somebody show me the best practice for running a script from within venv that will run my flask app?
Upvotes: 0
Views: 891
Reputation: 4059
You can dot source the pipenv with :
cd YourProjectPath
$venv = pipenv --venv
. "$venv\scripts\activate.ps1"
#"rest of your script"
$env:FLASK_APP = "./src/main.py"
flask run -h 0.0.0.0
if you are directly using venv , then:
. .\your env name\Scripts\Activate.ps1
#"rest of your script"
$env:FLASK_APP = "./src/main.py"
flask run -h 0.0.0.0
Upvotes: 1