Some basic concepts about python creating projects

When writing a project, it is usually to start running first, and then talk about it after running.
Many basic concepts are just known, and
I don’t know why they are written like this, but they can be written like this (or everyone writes like this) (I forgot why I wrote it like this, but I have to write it like this), so I feel it and save some time to write this article
.

Write python first today, take pycharm as an example.

build project

New Project

insert image description here

what project to build

insert image description here
People who are familiar with programming may know that there are some frameworks inside the rectangular red box on the left. I personally have more contact with front-end frameworks such as vue.

Pure Python

It means pure Python code, does not rely on external frameworks, and writes programs directly in Python.
The advantage is that it is lightweight, no need to install additional packages, and is suitable for small programs.
The disadvantage is that there is no framework support, and functions such as routing, templates, and databases need to be handled by themselves.
Suitable for small tools, scripts, simple crawlers, etc.

Django

Python's classic web framework has many users.
Based on the MVT mode, it provides templates, models, views, management background and other functions.
Database migration and admin background are very convenient. Abundant third-party libraries.
Over-design of small programs, there is a certain learning cost.
Suitable for medium and large websites, content management, news portals and other projects.

FastAPI

The latest generation of Python web framework, based on ASGI.
Ease of use, development speed and performance are all excellent.
Provide data validation based on Pydantic, using Type Hints.
Automatically generate API documentation for easy debugging.
Suitable for building high-performance, production-ready RESTful APIs.
Can also be used for small web applications.
After that is
Flask - a tiny web framework for Python, based on Werkzeug and Jinja2, suitable for the development of small projects.
Google App Engine - Google's PaaS platform that allows developers to easily build and run web applications on it.
Pyramid - A web framework for Python, with a modular and loosely coupled design, suitable for large projects.
Scientific Python - A series of Python libraries for scientific computing, such as NumPy, SciPy, Matplotlib, etc.
Angular CLI - Angular's command-line interface tool that makes it easy to create and manage Angular projects.
Bootstrap - The most popular front-end CSS framework, providing elegant CSS styles and JavaScript plugins.

Pure Python

insert image description here
When Python Interpreter builds a new project in PyCharm, it means to set the Python interpreter used by the project.
The purpose of PyCharm allowing you to set the interpreter is to let the IDE know which specific Python environment to use to run the code of this project.

tool virtualenv pipenv poetry
virtual environment Create and manage virtual environments Automatically create virtual environments Automatically create virtual environments
dependency management none Pipfile和Pipfile.lock pyproject.toml
packaging function none none Support for packaging to PyPI
cross-platform support all platforms Windows Compatibility Issues mainstream platform
Dependency analysis none none Visual dependency graph
Usage Common virtual environment tools Gradually replaced by poetry The community is active and has become a mainstream best practice

Conda provides a comprehensive cross-language environment management solution and is the first choice in the field of data science. Other tools focus more on the Python environment and package management.
Take virtualenv as an example

inherit global site-packages

inherit global site-packages
Whether to let the project's virtual environment inherit the site-packages of the global system.
site-packages is the directory Python uses to search for third-party modules and packages.

如果选中该选项:
	项目的虚拟环境会继承系统全局的site-packages。
	项目虚拟环境可以直接使用系统中已安装的第三方库。
	全局安装的库会对项目环境产生影响。
如果不选中该选项:
	项目虚拟环境会独立于全局site-packages。
	需要在项目虚拟环境内单独安装第三方库。
	项目环境和全局系统隔离,不会互相影响。
	通常在开发项目时,不建议选中该选项,而是让项目环境完全隔离。

This can avoid conflicts between library dependencies and versions of different projects in the system, and keep each project environment independent and consistent.

Make Available to All Projects

Make one interpreter/SDK available to all projects.
When you configure a new Python interpreter or SDK in PyCharm, by default it can only be used in the current project.
If you check the "Make Available to All Projects" option, then this interpreter/SDK will be available globally in the IDE and can be used by all projects.

for example:

你在项目A中配置了一个Python 3.7的解释器,没有勾选该选项。
则这个解释器只能在项目A中使用。
你在项目B中配置了一个Python 3.8的解释器,并勾选了该选项。
则项目A和项目B都可以选择使用这个Python 3.8解释器。
如果项目C想使用一个全局可用的解释器,可以在项目设置中直接选择,而无需重复配置。
所以,这个选项可以减少重复配置解释器/SDK的工作,将其变为IDE范围内的全局选项。
但同时要注意版本冲突问题。

In summary, this option controls whether an interpreter/SDK is visible and available to all projects in the IDE.

Previously configured interpreter

A Python interpreter that has been previously configured in this project.

When the Python interpreter needs to be configured multiple times in a PyCharm project, the IDE will record the previously configured interpreter.

Then when reconfiguring the interpreter, you can select the previously used interpreter from the "Previously configured interpreter" list without having to re-specify the path and details.
This simplifies the process of repeatedly configuring the same interpreter.

例如:
第一次配置项目时,你选择了Python 3.6 at /usr/bin/python3.6 作为解释器。
后来你切换到了Python 3.7。
此时如果需要重新使用3.6,可以直接从列表中选择"Python 3.6 at /usr/bin/python3.6",而不用手动再找一次路径。
PyCharm会记录这个项目中所有用过的解释器。
所以,这是一种通过记录历史配置来简化重复配置相同解释器的功能。

You can avoid having to manually fill in the details for each configuration.
Select a "Previously configured interpreter" to quickly switch to the previously used Python interpreter.

Create a main.py welcome script

Create a Python script that provides an entry point to coding in PyCharm
here is to create a simple main.py welcome script

Guess you like

Origin blog.csdn.net/m0_54765221/article/details/131802335