Python项目配置前的准备工作
安装miniconda
推荐大家使用清华镜像下载的miniconda,实测非常稳定,记得安装的时候所有的对号都要选择上。
https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_4.9.2-Windows-x86_64.exe
现在完成之后,直接命令行打开输入conda -V的指令观察是否能正确输出conda的版本号,如果可以,则说明没有问题。
另外,为了增加后面镜像下载的速度,推荐大家配置国内的镜像。
请执行下面的指令进行镜像的配置。
conda config --remove-key channels conda config--addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config--addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config--addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ conda config--setshow_channel_urlsyespip configsetglobal.index-url https://pypi.tuna.tsinghua.edu.cn/simple安装社区版本的pycharm
这里推荐大家安装社区版本的,社区版本的功能已经非常强大,并且完全免费。
下载的地址在这里:其他版本 - PyCharm
下载之后直接安装即可。
安装vs编译工具
后期在进行一些库的安装的过程中,可能出出现下面的错误。
error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio":https://visualstudio.microsoft.com/downloads/ Tools":出现这样的错误表示你的代码缺乏c++的编译工具,因为部分库的底层实现逻辑是通过C++来进行完成的,所以为了避免出现这样的错误,在前期的准备中,我们需要从官网下载对应的库进行安装:Microsoft C++ 生成工具 - Visual Studio
下载之后双击进行安装,你需要从列表中选择下面的部分,注意,这里的安装位置默认在c盘,如果你的c盘没有足够的空间,你一定要给他移动他其他的盘中。
安装完成之后重启你的电脑即可。
装字体文件(可选)
另外,很多小伙伴在跑yolo的时候,会提示字体文件缺失,虽然程序设置了自动下载,但是因为国内的下载速度比较慢,所以大家还是提前进行安装,字体文件已经提前准备在了代码包中,大家从字体文件的目录打开,双击进行安装即可。
没有字体包的小伙伴可以直接从本博客的资源链接中获取。
一些常用的深度学习库的安装指令
condainstallpytorch==1.8.0 torchvision torchaudiocudatoolkit=10.2# 注意这条命令指定Pytorch的版本和cuda的版本condainstallpytorch==1.10.0 torchvision torchaudiocudatoolkit=11.3# 30系列以上显卡gpu版本pytorch安装指令condainstallpytorch==1.8.0torchvision==0.9.0torchaudio==0.8.0 cpuonly# CPU的小伙伴直接执行这条命令即可pipinstalltorch==1.10.0torchvision==0.11.0torchaudio==0.10.0 pipinstalltorch==1.8.0torchvision==0.9.0torchaudio==0.8.0 pipinstalltorch==2.1.0torchvision==0.16.0torchaudio==2.1.0 condainstallpytorch==2.1.0torchvision==0.16.0torchaudio==2.1.0-cpytorch pipinstalltorch==2.1.0torchvision==0.16.0torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cpu更换配置文件(可选)
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license # Overview: # This pyproject.toml file manages the build, packaging, and distribution of the Ultralytics library. # It defines essential project metadata, dependencies, and settings used to develop and deploy the library. # Key Sections: # - [build-system]: Specifies the build requirements and backend (e.g., setuptools, wheel). # - [project]: Includes details like name, version, description, authors, dependencies and more. # - [project.optional-dependencies]: Provides additional, optional packages for extended features. # - [tool.*]: Configures settings for various tools (pytest, yapf, etc.) used in the project. # Installation: # The Ultralytics library can be installed using the command: 'pip install ultralytics' # For development purposes, you can install the package in editable mode with: 'pip install -e .' # This approach allows for real-time code modifications without the need for re-installation. # Documentation: # For comprehensive documentation and usage instructions, visit: https://docs.ultralytics.com [build-system] requires = ["setuptools>=70.0.0,<=82.0.1", "wheel"] build-backend = "setuptools.build_meta" # Project settings ----------------------------------------------------------------------------------------------------- [project] name = "ultralytics" dynamic = ["version"] description = "Ultralytics YOLO 🚀 for SOTA object detection, multi-object tracking, instance segmentation, pose estimation, classification, and oriented object detection." readme = "README.md" requires-python = ">=3.8" license = { "text" = "AGPL-3.0" } keywords = ["machine-learning", "deep-learning", "computer-vision", "ML", "DL", "AI", "RT-DETR", "SAM3", "YOLO", "YOLOv3", "YOLOv5", "YOLOv8", "YOLO11", "YOLO26", "Platform", "Ultralytics"] authors = [ { name = "Glenn Jocher", email = "glenn.jocher@ultralytics.com" }, { name = "Jing Qiu", email = "jing.qiu@ultralytics.com" }, ] maintainers = [ { name = "Ultralytics", email = "hello@ultralytics.com" }, ] classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: Education", "Intended Audience :: Science/Research", "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Topic :: Software Development", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Artificial Intelligence", "Topic :: Scientific/Engineering :: Image Recognition", "Operating System :: POSIX :: Linux", "Operating System :: MacOS", "Operating System :: Microsoft :: Windows", ] # Required dependencies ------------------------------------------------------------------------------------------------ dependencies = [ "numpy>=1.23.0", "matplotlib>=3.3.0", "opencv-python>=4.6.0,!=4.13.0.90", # 4.13.0.90 FIPS selftest crash https://github.com/ultralytics/ultralytics/issues/23373 "pillow>=7.1.2", "pyyaml>=5.3.1", "requests>=2.23.0", "torch>=1.8.0", "torch>=1.8.0,!=2.4.0; sys_platform == 'win32'", # Windows CPU errors w/ 2.4.0 https://github.com/ultralytics/ultralytics/issues/15049 "torchvision>=0.9.0", "psutil>=5.8.0", # system utilization "polars>=0.20.0", "nvidia-ml-py>=12.0.0", # NVIDIA GPU monitoring https://pypi.org/project/nvidia-ml-py "ultralytics-thop>=2.0.18", # FLOPs computation https://github.com/ultralytics/thop ] # Optional dependencies ------------------------------------------------------------------------------------------------ [project.optional-dependencies] dev = [ "ipython", "pytest", "pytest-cov", "pytest-xdist>=3.0.0", "coverage[toml]", "zensical>=0.0.15; python_version >= '3.10'", "mkdocs-ultralytics-plugin>=0.2.5", # for meta descriptions and images, dates and authors "minijinja>=2.0.0", # render docs macros without mkdocs-macros-plugin ] export-base = [ "onnx>=1.12.0; platform_system != 'Darwin'", # ONNX export "onnx>=1.12.0,<1.18.0; platform_system == 'Darwin' and python_version < '3.13'", # TF inference hanging on MacOS (tested up to onnx==1.20.0) "onnx>=1.20.0; platform_system == 'Darwin' and python_version >= '3.13'", "onnxslim>=0.1.82", # ONNX export validation and inference. Jetson jobs provide custom aarch64 onnxruntime-gpu wheels. "onnxruntime<1.20.0; python_version < '3.11' and (platform_machine != 'aarch64' or platform_system != 'Linux')", "onnxruntime>=1.20.0; python_version >= '3.11'", "nncf>=2.14.0,<3.0.0; python_version >= '3.9'", # OpenVINO INT8 export "openvino>=2024.0.0", # OpenVINO export "packaging>=26.0; platform_machine == 'aarch64' and platform_system == 'Linux' and python_version >= '3.9'", # IMX export bug ] export-legacy-torch = [ "numpy<2", "setuptools<81.0.0; python_version >= '3.9'", # legacy torch's torch_version imports pkg_resources, removed in setuptools>=81 ] export-tensorflow = [ "numpy<2.0.0; python_version < '3.13'", # TF 2.20 compatibility "tensorflow>=2.0.0,<=2.19.0; python_version < '3.13'", # TF bug https://github.com/ultralytics/ultralytics/issues/5161 "tensorflow>2.19.0; python_version >= '3.13'", "ydf<0.13.0; platform_machine != 'aarch64' and python_version <= '3.12'", # ydf>=0.13 has protobuf gencode 6.x but tensorflow<=2.19 requires protobuf<6 "googleapis-common-protos<1.74.0; python_version <= '3.12'", # >=1.74.0 uses protobuf gencode 7.34.1, incompatible with tensorflow<=2.19 (protobuf<6) and breaks ray[tune] import "tensorstore>=0.1.63; platform_machine == 'aarch64' and python_version >= '3.9'", # for TF Raspberry Pi exports "h5py!=3.11.0; platform_machine == 'aarch64'", # fix h5py build issues due to missing aarch64 wheels in 3.11 release ] export-coreml = [ "numpy<=2.3.5; platform_system != 'Windows' and python_version <= '3.13'", # pin until CoreML>9.0 fixes numpy>=2.4 int() cast crash "coremltools>=9.0; platform_system != 'Windows' and python_version <= '3.13'", # CoreML supported on macOS and Linux "scikit-learn>=1.3.2; platform_system != 'Windows' and python_version <= '3.13'", # CoreML k-means quantization ] export-executorch = [ "executorch", "torch>=2.12.0,<2.13.0; platform_system == 'Linux' and platform_machine == 'aarch64'", "numpy<=2.3.5", ] export-deepx = [ "dx_com", "numpy<2", ] export-litert = [ # LiteRT export, Linux x86 and macOS (litert-torch trace + ai-edge-litert/quantizer) "litert-torch>=0.9.0; (platform_system == 'Linux' and platform_machine == 'x86_64') or platform_system == 'Darwin'", "ai-edge-litert>=2.1.4; (platform_system == 'Linux' and platform_machine == 'x86_64') or platform_system == 'Darwin'", "ai-edge-quantizer>=0.6.0; (platform_system == 'Linux' and platform_machine == 'x86_64') or platform_system == 'Darwin'", ] export = [ "ultralytics[export-base]", "ultralytics[export-tensorflow]", "ultralytics[export-coreml]", "ultralytics[export-litert]", # Raspberry Pi Python 3.11 ExecuTorch inference requires the last known-good Linux ARM64 Torch 2.12 stack. "torch>=2.12.0,<2.13.0; platform_system == 'Linux' and platform_machine == 'aarch64' and python_version == '3.11'", ] solutions = [ "shapely>=2.0.0", # shapely for point and polygon data matching "lap>=0.5.12", # for solution tracking linear assignment # CLIP for similarity search auto-installs on first use via ultralytics.nn.text_model (https://github.com/ultralytics/CLIP) "streamlit>=1.51.0; python_version >= '3.10'", # for live inference on web browser, i.e `yolo streamlit-predict` "streamlit>=1.29.0,<1.51.0; python_version < '3.10' and (platform_machine != 'aarch64' or platform_system != 'Linux')", "flask>=3.0.1", # for similarity search solution ] logging = [ "wandb", # https://docs.ultralytics.com/integrations/weights-biases/ "tensorboard", # https://docs.ultralytics.com/integrations/tensorboard/ "mlflow", # https://docs.ultralytics.com/integrations/mlflow/ ] extra = [ "ipython", # interactive notebook "albumentations>=1.4.6", # training augmentations "faster-coco-eval>=1.6.7", # COCO mAP ] typing = [ "types-pillow", "types-psutil", "types-pyyaml", "types-requests", "types-shapely", ] [project.urls] "Homepage" = "https://ultralytics.com" "Source" = "https://github.com/ultralytics/ultralytics" "Documentation" = "https://docs.ultralytics.com" "Bug Reports" = "https://github.com/ultralytics/ultralytics/issues" "Changelog" = "https://github.com/ultralytics/ultralytics/releases" [project.scripts] yolo = "ultralytics.cfg:entrypoint" ultralytics = "ultralytics.cfg:entrypoint" # Tools settings ------------------------------------------------------------------------------------------------------- [tool.setuptools] # configuration specific to the `setuptools` build backend. packages = { find = { where = ["."], include = ["ultralytics", "ultralytics.*"] } } # Tests included below for checking Conda builds in https://github.com/conda-forge/ultralytics-feedstock package-data = { "ultralytics" = ["**/*.yaml", "**/*.sh", "../tests/*.py"], "ultralytics.assets" = ["*.jpg"], "ultralytics.solutions.templates" = ["*.html"]} [tool.setuptools.dynamic] version = { attr = "ultralytics.__version__" } [tool.pytest.ini_options] addopts = "--doctest-modules --durations=30 --color=yes" markers = [ "slow: skip slow tests unless --slow is set", ] norecursedirs = [".git", "dist", "build"] [tool.coverage.run] source = ["ultralytics/"] data_file = "tests/.coverage" omit = ["ultralytics/utils/callbacks/*"] [tool.isort] line_length = 120 multi_line_output = 0 [tool.yapf] based_on_style = "pep8" spaces_before_comment = 2 column_limit = 120 coalesce_brackets = true spaces_around_power_operator = true space_between_ending_comma_and_closing_bracket = true split_before_closing_bracket = false split_before_first_argument = false [tool.ruff] line-length = 120 [tool.ruff.format] docstring-code-format = true [tool.ruff.lint.pydocstyle] convention = "google" [tool.docformatter] wrap-summaries = 120 wrap-descriptions = 120 pre-summary-newline = true close-quotes-on-newline = true in-place = true [tool.codespell] ignore-words-list = "grey,writeable,finalY,RepResNet,Idenfy,WIT,Smoot,EHR,ROUGE,ALS,iTerm,Carmel,FPR,Hach,Calle,ore,COO,MOT,crate,nd,ned,strack,dota,ane,segway,fo,gool,winn,commend,bloc,nam,afterall,skelton,goin,alls" skip = "*.pt,*.pth,*.torchscript,*.onnx,*.tflite,*.pb,*.bin,*.param,*.mlmodel,*.engine,*.npy,*.data*,*.csv,*pnnx*,*venv*,*translat*,*lock*,__pycache__*,*.ico,*.jpg,*.png,*.webp,*.avif,*.mp4,*.mov,/runs,/.git,./docs/??/*.md,./docs/mkdocs_??.yml"