當你安裝一個應用程式時,你通常是在安裝一個軟體包,其中包含應用程式的可執行程式碼和重要文件,如文件、圖示等。在Linux上,軟體一般被打包成RPM 或DEB 等格式,使用者只要透過 dnf
# 或 apt
等指令就可以進行安裝了,這取決於你使用的Linux 發行版。然而幾乎每天都有新的 Python 模組發布,因此你很容易遇到一個尚未打包的 Python 模組。這就是 pyp2rpm
存在的意義了。
最近我在嘗試安裝一個叫 python-concentration
的模組,但是進展並不太順利:
$ sudo dnf install python-concentration Updating Subscription Management repositories. Last metadata expiration check: 1:23:32 ago on Sat 11 Jun 2022 06:37:25. No match for argument: python-concentration Error: Unable to find a match: python-concentration
雖然這是一個發佈在PyPi的包,但它仍不能被打包成RPM 包。好消息是你可以使用 pyp2rpm
以相對簡單的過程將它打包成 RPM 包。
首先你需要設定兩個目錄:
$ mkdir rpmbuild $ cd rpmbuild && mkdir SPECS
像這樣去安裝 pyp2rpm
:
$ sudo dnf install pyp2rpm
1、產生spec 檔案
RPM 套件的基礎是一種spec 文件,這個文件包含你創建這個包的所有信息,如所需的依賴關係、應用的版本號、安裝的文件等信息。當指向某個 Python 模組時,pyp2rpm
會為它建立一個 spec 文件,你可以用它來建立 RPM 套件。
下面以 python-concentration
為例示範如何建立一個spec 檔案:
$ pyp2rpm concentration > ~/rpmbuild/SPECS/concentration.spec
下面是它產生的檔案:
# Created by pyp2rpm-3.3.8 %global pypi_name concentration %global pypi_version 1.1.5 Name: python-%{pypi_name} Version:%{pypi_version} Release:1%{?dist} Summary:Get work done when you need to, goof off when you don't License:None URL:None Source0:%{pypi_source} BuildArch:noarch BuildRequires:python3-devel BuildRequires:python3dist(setuptools) %description Concentration [ >= 2.6.1 with python3dist(hug) < 3~~) Requires: python3dist(setuptools) %description -n python3-%{pypi_name} Concentration [需要記錄日期。
%changelog * Sat Jun 11 2022 Tux <tux@example.com> - 1.1.5-1
再次運行 rpmint
#:
$ rpmlint ~/rpmbuild/SPEC/concentration.spec 0 packages and 1 specfiles checked; 0 errors, 0 warnings.
成功!
3、下載原始碼
你需要下載好打包的程式碼才能進一步建置 RPM 套件。一個簡單的方式是解析你的 spec 檔案以取得原始碼的網址。
首先,透過 dnf
# 安裝 spectool
#:
$ sudo dnf install spectool
然后通过 spectool
来下载源码:
$ cd ~/rpmbuild $ spectool -g -R SPEC/concentration.spec Downloading: https://files.pythonhosted.org/...concentration-1.1.5.tar.gz 6.0 KiB / 6.0 KiB[=====================================] Downloaded: concentration-1.1.5.tar.gz
这样就创建了一个 SOURCES
目录并将源码放入其中。
4、构建源软件包
现在你已经验证过 spec 文件了,接下来就可以通过 rpmbuild
构建源软件包了。如果你还没有安装 rpmbuild
,你也可以通过 dnf
安装 rpm-build
包(或者在使用 rpmbuild
命令时根据终端的的提示进行安装)。
参数 -bs
表示构建源软件包。添加这个参数会产生一个 src.rpm 文件,这是一个用于为特定架构重新构建的通用包:
$ rpmbuild -bs SPECS/concentration.spec Wrote: ~/rpmbuild/SRPMS/python-concentration-1.1.5-1.el9.src.rpm
为你的系统构建一个可安装的 RPM 文件:
$ rpmbuild –rebuild SRPMS/python-concentration-1.1.5-1.el9.src.rpm error: Failed build dependencies: python3-devel is needed by python-concentration-1.1.5-1.el9.noarch
看起来这个包需要安装 Python 的开发库才能继续构建。安装它们以继续构建。这一次,构建成功了,并且渲染了更多的输出(为了清楚起见,我在这里简略了输出):
$ sudo dnf install python3-devel -y $ rpmbuild –rebuild SRPMS/python-concentration-1.1.5-1.el9.src.rpm [...] Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.TYA7l2 + umask 022 + cd /home/bogus/rpmbuild/BUILD + rm -rf concentration-1.1.5 + RPM_EC=0 ++ jobs -p + exit 0
你的 RPM 包现在已经构建在 RPMS
子目录下,像平常一样使用 dnf
安装它。
$ sudo dnf install RPMS/noarch/python3-concentration*rpm
为什么不使用 PyPi?
通常情况下我们并不需要将 Python 模块打包成 RPM 包。通过 PyPi 来安装模块也是可以接受的,但是 PyPi 会安装额外的包管理器对你的模块进行检查和更新。当你使用 dnf
来安装 RPM 包时,你在安装完成时就能够获取到完整的安装列表。有了 pyp2rpm
之后,这个过程就变得快速、简单且自动化了。
以上是四步驟打包一個新的 Python 模組的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通過使用pyenv、venv和Anaconda來管理不同的Python版本。 1)使用pyenv管理多個Python版本:安裝pyenv,設置全局和本地版本。 2)使用venv創建虛擬環境以隔離項目依賴。 3)使用Anaconda管理數據科學項目中的Python版本。 4)保留系統Python用於系統級任務。通過這些工具和策略,你可以有效地管理不同版本的Python,確保項目順利運行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基於基於duetoc的iMplation,2)2)他們的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函數函數函數函數構成和穩定性構成和穩定性的操作,製造

數組的同質性對性能的影響是雙重的:1)同質性允許編譯器優化內存訪問,提高性能;2)但限制了類型多樣性,可能導致效率低下。總之,選擇合適的數據結構至關重要。

到CraftCraftExecutablePythcripts,lollow TheSebestPractices:1)Addashebangline(#!/usr/usr/bin/envpython3)tomakethescriptexecutable.2)setpermissionswithchmodwithchmod xyour_script.3)

numpyArraysareAreBetterFornumericalialoperations andmulti-demensionaldata,而learthearrayModuleSutableforbasic,內存效率段

numpyArraySareAreBetterForHeAvyNumericalComputing,而lelethearRayModulesiutable-usemoblemory-connerage-inderabledsswithSimpleDatateTypes.1)NumpyArsofferVerverVerverVerverVersAtility andPerformanceForlargedForlargedAtatasetSetsAtsAndAtasEndCompleXoper.2)

ctypesallowscreatingingangandmanipulatingc-stylarraysinpython.1)usectypestoInterfacewithClibrariesForperfermance.2)createc-stylec-stylec-stylarraysfornumericalcomputations.3)passarraystocfunctions foreforfunctionsforeffortions.however.however,However,HoweverofiousofmemoryManageManiverage,Pressiveo,Pressivero


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

Atom編輯器mac版下載
最受歡迎的的開源編輯器