Python tips for configuring project migration and deployment based on the Flask framework and dependency package information, pythonflask
After Coding Based on the Flask framework on the local machine, you need to deploy the code on the specified server if you need interfaces or data operations.
In general, most developers who use the Flask framework use the Python virtual environment to run projects. Different virtual environments have different configuration dependency package information. If you re-migrate to a new virtual environment and re-configure the dependency packages one by one, it will be a waste of time.
Next we will introduce a simple and easy-to-use technique that I can see in my own books to avoid having to read books every time I configure it. Therefore, I will write an article for record by myself, I hope to help other students.
After coding the project, open the local CMD and enter the project Virtual Environment Scripts directory. The specific operations are as follows:
Input
cd E:\WorkPlace\Git_python\MyDemo-ten\venv\Scripts
Enter the directory specified by the command above.
Then enter the command
activate
(PS: This command will display the virtual environment name before the path. For example, if my virtual environment name is venv, it will display (venv )).
Then enter the command cd ..
Enter the command cd again. (PS: cd .. indicates that the upper-level directory is returned. Two operations are performed to enter the root directory of the project ).
Finally, enter the command
pip freeze >requirements.txt
You can see a requirements.txt file under the project root directory. The file displays information about all configuration dependency packages of the project. For details, see:
Open ID e requirements.txt. For details, refer:
After the migration to a new environment, If you enable it with id e, the ID e will prompt the specified dependency package in the configuration and installation requirements.txt information, and click Install in the installation prompt. If you do not have a prompt or do not use id eto configure the environment, you can perform the operations in the newly created virtual environment from the environment, which is similar to creating the requirements.txt file in the Environment configuration, and then enter the command:
pip install -r requirements.txt
You can complete the dependency package configuration.