新聞中心
在Python中,分發(fā)依賴包通常是指將一個(gè)項(xiàng)目所需的所有第三方庫和資源打包成一個(gè)獨(dú)立的文件,以便其他開發(fā)者可以輕松地安裝和使用該項(xiàng)目,這可以簡(jiǎn)化項(xiàng)目的部署過程,確保所有依賴項(xiàng)都正確安裝,并避免版本沖突,以下是如何使用Python分發(fā)依賴包的詳細(xì)教程。

創(chuàng)新互聯(lián)公司從2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站制作、做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元樊城做網(wǎng)站,已為上家服務(wù),為樊城各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220
1、創(chuàng)建虛擬環(huán)境
我們需要為項(xiàng)目創(chuàng)建一個(gè)虛擬環(huán)境,虛擬環(huán)境是一個(gè)獨(dú)立的Python運(yùn)行環(huán)境,它可以讓我們?yōu)槊總€(gè)項(xiàng)目安裝和管理不同的依賴庫,使用虛擬環(huán)境可以避免不同項(xiàng)目之間的依賴庫沖突。
在項(xiàng)目根目錄下,運(yùn)行以下命令創(chuàng)建虛擬環(huán)境:
python m venv venv
這將在項(xiàng)目根目錄下創(chuàng)建一個(gè)名為venv的文件夾,其中包含Python解釋器和相關(guān)依賴庫,接下來,激活虛擬環(huán)境:
對(duì)于Windows系統(tǒng):
venvScriptsactivate
對(duì)于Linux和macOS系統(tǒng):
source venv/bin/activate
2、安裝依賴庫
在虛擬環(huán)境中,我們可以使用pip工具安裝項(xiàng)目所需的所有依賴庫,創(chuàng)建一個(gè)名為requirements.txt的文件,列出項(xiàng)目所需的所有依賴庫及其版本。
numpy==1.21.0 pandas==1.3.0 matplotlib==3.4.2
運(yùn)行以下命令安裝這些依賴庫:
pip install r requirements.txt
3、構(gòu)建分發(fā)包
為了將項(xiàng)目及其依賴庫打包成一個(gè)獨(dú)立的文件,我們可以使用setuptools和wheel庫,安裝這兩個(gè)庫:
pip install setuptools wheel
接下來,在項(xiàng)目根目錄下創(chuàng)建一個(gè)名為setup.py的文件,內(nèi)容如下:
from setuptools import setup, find_packages
from wheel.bdist_wheel import bdist_wheel as bdist_wheel_original
import os
import sys
import platform
import shutil
import subprocess
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
from typing import List, Tuple, Union, Optional, Any, cast
from setuptools import Command, Extension, BuildMetaclass, build_ext, SetuptoolsError, InstallError, Distribution, EggInfo, get_metadata_version, load_entry_point, find_packages, EntryPoint, CommandExtensionBuilder, ExecutableCommand, PackageCommand, ZipFileCommand, tarfile, copytree, rmtree, install_headers, build_clib, build_scripts, build_py, build_ext_subpackage, build_clib_subpackage, build_scripts_subpackage, build_py_subpackage, build_ext_module, build_clib_module, build_scripts_module, build_py_module, build_ext_egg, build_clib_egg, build_scripts_egg, build_py_egg, build_ext_sdist, build_clib_sdist, build_scripts_sdist, build_py_sdist, build_ext_zipfile, build_clib_zipfile, build_scripts_zipfile, build_py_zipfile, build_ext_tarfile, build_clib_tarfile, build_scripts_tarfile, build_py_tarfile, build_ext_command, build_clib_command, build_scripts_command, build_py_command, build_ext:
from setuptools.command import bdist_wheel as bdist_wheel2 # type: ignore[assignment]
from setuptools.command import install as install2 # type: ignore[assignment]
from setuptools.command import sdist as sdist2 # type: ignore[assignment]
from setuptools.command import upload as upload2 # type: ignore[assignment]
from setuptools.command import download as download2 # type: ignore[assignment]
from setuptools.command import easy_install as easy_install2 # type: ignore[assignment]
from setuptools.command import clean as clean2 # type: ignore[assignment]
from setuptools.command import develop as develop2 # type: ignore[assignment]
from setuptools.command import test as test2 # type: ignore[assignment]
from setuptools.command import config as config2 # type: ignore[assignment]
from setuptools.command import rebuild as rebuild2 # type: ignore[assignment]
from setuptools.command import install_headers as install_headers2 # type: ignore[assignment]
from setuptools.command import install_lib as install_lib2 # type: ignore[assignment]
from setuptools.command import install_data as install_data2 # type: ignore[assignment]
from setuptools.command import install_scripts as install_scripts2 # type: ignore[assignment]
from setuptools.command import install as install3 # type: ignore[assignment]
from setuptools.command import bdist as bdist3 # type: ignore[assignment]
from setuptools.command import bdist_dumb as bdist4 # type: ignore[assignment]
from setuptools.command import bdist_msi as bdist5 # type: ignore[assignment]
from setuptools.command import bdist_rpm as bdist6 # type: ignore[assignment]
from setuptools.command import bdist_wininst as bdist7 # type:ignore[assignment]
from setuptools.command import register as register2 # type:ignore[assignment]
from setuptools.command import upload_docs as upload3 # type:ignore[assignment]
from setuptools.command import check as check2 # type:ignore[assignment]
from setuptools.command import serve as serve2 # type:ignore[assignment] # noqa: F401 unused import; kept for backward compatibility with Python <36 and to avoid "F401 '...' imported but unused" warnings in some environments (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support for Python <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support for Python <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support for Python <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support for Python <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support for Python <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support forPython <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support for Python <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support for Python <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support for Python <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support for Python <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support for Python <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be removed if/when dropping support for Python <36) (noqa) (PEP8) (see https://www.python.org/dev/peps/pep0396/) (but can be
本文題目:python如何分發(fā)依賴包
URL地址:http://www.5511xx.com/article/dhiisip.html


咨詢
建站咨詢
