2014-01-17 14 views
2

林..包在setup.py文件下面就Python包的教程,並試圖瞭解什麼是「包」線在這裏做

install_requires將安裝在列表中給出的所有軟件...所以,軟件包有什麼作用?

from distutils.core import setup 

setup(
    name='TowelStuff', 
    version='0.1.0', 
    author='J. Random Hacker', 
    author_email='[email protected]', 
    packages=['towelstuff', 'towelstuff.test'], 
    scripts=['bin/stowe-towels.py','bin/wash-towels.py'], 
    url='http://pypi.python.org/pypi/TowelStuff/', 
    license='LICENSE.txt', 
    description='Useful towel-related stuff.', 
    long_description=open('README.txt').read(), 
    install_requires=[ 
     "Django >= 1.1.1", 
     "caldav == 0.1.4", 
    ], 
) 

回答

2

你可以看看disutils文檔的這一部分,它給出了全面的解釋:http://docs.python.org/2/distutils/setupscript.html#listing-whole-packages

但在短期,「包」是指代碼,而不是外部依賴性。如果你的setup.py文件住在你的項目的頂層目錄,和你的「包」參數列表towelstuff和towelstuff.test,這裏的目錄結構應該是什麼樣子:

setup.py 
towelstuff 
    __init__.py 
    ...some other files in towelstuff... 
towelstuff.test 
    __init__.py 
    ...some other files in towelstuff.test... 
...some other scripts in the project directory... 

基本上,一個Python包只是一個包含'__init__.py'文件的目錄。當你編寫setup.py文件時,你可能會看到setup.py文件中有兩個軟件包(towelstuff和towelstuff.test),它們與setup.py腳本位於同一個目錄中。

將來,當您使用setup.py捆綁應用程序時,這兩個軟件包將包含在發行版中。

+0

+1你的回答比我的更清楚。 (刪除我的)。 – mshildt

相關問題