簡體   English   中英

Python無需安裝即可共享模塊

[英]Python share a module without installation

我想使用具有一些C代碼和python代碼的外部模塊(psutil)。 在我的本地計算機上,我已經使用Mingw安裝了此模塊。 現在,我想在其他計算機上使用該庫(而不必在每台計算機上安裝它)。 因此,我可以將編譯后的代碼復制到一個公共位置,然后再從其他計算機復​​制到sys.path並應該能夠使用它嗎?

我一直在尋找使用庫的正確方法,而不必在每台機器上都安裝它,到目前為止,我發現使用bdist選項,但這會創建一個zip文件,並且我認為它需要在每台機器上解壓縮。

有人可以幫我什么應該遵循的最佳方法。 我知道,我可以使用Pyinstaller,Py2exe,但是我的其他機器上都裝有python,而我只想使用此模塊而不必在任何地方安裝它。

使用雞蛋我取得了成功。 您可以創建所有其他模塊的卵,將它們放在某個目錄中,然后只需將該目錄添加到sys.path ,然后導入卵。 由於那里有C擴展名, 您可能需要使用 pkg_resources模塊

這樣做的好處是,它可以很好地分離和封裝其他代碼。

有關此答案的更多信息。

bdist與正確的選項一起使用: 從文檔中:

The available formats for built distributions are:

Format      Description                  Notes
gztar       gzipped tar file (.tar.gz)   (1),(3)
ztar        compressed tar file (.tar.Z) (3)
tar         tar file (.tar)              (3)
zip         zip file (.zip)              (2),(4)
rpm         RPM                          (5)
pkgtool     Solaris pkgtool  
sdux        HP-UX swinstall  
wininst     self-extracting ZIP file for Windows (4)
msi         Microsoft Installer.

Notes:
1. default on Unix
2. default on Windows
3. requires external utilities: tar and possibly one of gzip, bzip2, or compress
4. requires either external zip utility or zipfile module (part of the standard Python library since Python 1.6)
5. requires external rpm utility, version 3.0.4 or better (use rpm --version to find out which version you have)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM