Reputation: 301
I changed the location and changed name of my flask folder, which contains a virtual envrionment.
flask run
Fatal error in launcher: Unable to create process using '"c:\previous\path\backend_flask\.venv\scripts\python.exe" "C:\current\path\flask_backend\.venv\Scripts\flask.exe" run': The system cannot find the file specified.
However,
python -m flask run
still works.
Here is my project structure. .venv
folder is a neighbor of app
folder.
├── app
│ ├── __init__.py
│ ├── database.py
│ ├── routes.py
│ └── templates
│ └── index.html
├── README.md
├── .gitignore
├── output.txt
└── main.py
How can I fix the error from the flask run
command?
Upvotes: 1
Views: 1473
Reputation: 301
As answered here, there is no clean way to relocate a virtual environment. The flask is installed in the virtual environment and when I run flask run
, the virtual environment files cannot find the executables because of the relocation. The same problem occurs if I run pip
with virtual environment activated.
Python 3.9
I summaries the solution here, this works regardless whether or not you have relocated. (in my case I am able to freeze
with python -m pip freeze
even though pip freeze
doesn't work).
python -m pip freeze > requirements.txt
to record your current dependencies. Make sure it records the environment in your virtual environment instead of your local environment. (make sure you activate virtual venv before freeze).rm -r <folder name>
python -m venv <name of env>
requirement
file you just created:
python -m pip install -r ./requirements.txt
Upvotes: 1