2012-12-11 279 views
1

我剛剛用setuptool做了一個Python包,但是我面臨一個問題,如果我預先安裝了Ubuntu庫中的所有工具,但是當我使用PyPi時,安裝失敗,因爲PyPi只包含源代碼,需要編譯,所以在安裝過程中有很多錯誤源。我如何在我的軟件包安裝過程中安裝Ubuntu軟件包?我的想法是subprocess,有沒有更好的方法?如何在安裝程序中安裝PyPi的Ubuntu軟件包?

EDITED

該錯誤消息

Reading http://pypi.python.org/simple/enable/ 
Reading http://code.enthought.com/projects/enable 
Best match: enable 4.2.0 
Downloading http://www.enthought.com/repo/ets/enable-4.2.0.tar.gz 
Processing enable-4.2.0.tar.gz 
Writing /tmp/easy_install-wuMg8s/enable-4.2.0/setup.cfg 
Running enable-4.2.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-wuMg8s/enable-4.2.0/egg-dist-tmp-LbjqHY 
/usr/lib/python2.7/dist-packages/numpy/distutils/system_info.py:548: UserWarning: Specified path /usr/local/include/python2.7 is invalid. 
    warnings.warn('Specified path %s is invalid.' % d) 
/usr/lib/python2.7/dist-packages/numpy/distutils/system_info.py:548: UserWarning: Specified path is invalid. 
    warnings.warn('Specified path %s is invalid.' % d) 
Warning: distutils distribution has been initialized, it may be too late to add a library freetype2_srcWarning: distutils distribution has been initialized, it may be too late to add a library agg24_srcWarning: distutils distribution has been initialized, it may be too late to add a library kiva_srcWarning: distutils distribution has been initialized, it may be too late to add an extension _agg/usr/lib/python2.7/dist-packages/numpy/distutils/system_info.py:548: UserWarning: Specified path /usr/X11R6/lib is invalid. 
    warnings.warn('Specified path %s is invalid.' % d) 
/usr/lib/python2.7/dist-packages/numpy/distutils/system_info.py:548: UserWarning: Specified path /usr/X11/lib is invalid. 
    warnings.warn('Specified path %s is invalid.' % d) 
/usr/lib/python2.7/dist-packages/numpy/distutils/system_info.py:548: UserWarning: Specified path /usr/X11R6/include is invalid. 
    warnings.warn('Specified path %s is invalid.' % d) 
/usr/lib/python2.7/dist-packages/numpy/distutils/system_info.py:548: UserWarning: Specified path /usr/X11/include is invalid. 
    warnings.warn('Specified path %s is invalid.' % d) 
error: X11 libraries not found. 

安裝腳本:

from setuptools import setup 

setup( 
    name = 'SomeName', 
    version = '0.1', 
    packages = ['src'], 
    author = 'Some Author', 
    maintainer = 'Some', 
    maintainer_email = '[email protected]', 
    description = '', 
    url = 'www.some.com', 
    install_requires = ['envisage >= 4.0', 
         'pyface >= 4.0', 
         'apptools >= 4.0', 
         'chaco >= 4.0', 
         'traits >= 4.0', 
         'traitsui >= 4.0', 
         'mysql-connector-python >= 1.0', 
         'pysnmp >= 4.2', 
         'pyasn1 >= 0.1.4', 
         'M2Crypto >= 0.21.1', 
         'netifaces >= 0.7' 

         ], 
) 
+0

從PyPi安裝應該可以正常工作。我認爲你做錯了什麼。 – Sibi

+0

如果您提供錯誤信息,可能對我們有幫助。 – Sibi

+0

我發佈了錯誤訊息 –

回答

1

從apt倉庫安裝下載的二進制文件已經包含所需的系統庫。如果沒有,apt Manager會確保安裝任何系統庫。使用setuptools(pip或easy_install)進行安裝只需獲取python的要求;而不是構建/系統要求。

就你而言,錯誤是error: X11 libraries not found.這意味着X11的構建頭文件在系統中不可用。解決這個問題的一個簡單方法是告訴apt只下載和安裝包(而不是包)本身的依賴關係。這將確保當你使用pip或easy_install時,Python會找到它需要的一切。例如,psycopg2是Postgresql的Python庫。要構建它,你需要postgresql支持庫(頭文件和文件)。這些不可用於PyPi。 debian軟件包python-psycopg2將正確安裝所有外部要求。現在,如果我想在虛擬環境中安裝psycopg2,我首先要確保我的系統擁有所有的外部要求建立包,所以我運行此命令:

sudo apt-get build-dep python-pyscopg2

這將只安裝依賴關係(所有支持標題),以便我可以稍後手動安裝它。

在你的情況,你應該運行apt-get build-dep python-enable,以及所需的一切將取回:

# apt-get build-dep python-enable 
Reading package lists... Done 
Building dependency tree 
Reading state information... Done 
The following NEW packages will be installed: 
    cdbs libblas3gf libdrm-intel1 libdrm-radeon1 libdrm2 libfreetype6-dev 
    libgl1-mesa-dev libgl1-mesa-dri libgl1-mesa-glx libglu1-mesa 
    libglu1-mesa-dev liblapack3gf libpaper-utils libpaper1 libpthread-stubs0 
    libpthread-stubs0-dev libx11-dev libxau-dev libxcb1-dev libxdamage1 
    libxdmcp-dev libxfixes3 libxslt1.1 libxxf86vm1 mesa-common-dev 
    python-chardet python-docutils python-lxml python-numpy python-pygments 
    python-pyrex python-roman python-setupdocs python-sphinx swig x11-common 
    x11proto-core-dev x11proto-input-dev x11proto-kb-dev xtrans-dev 
0 upgraded, 40 newly installed, 0 to remove and 0 not upgraded. 
Need to get 35.5 MB of archives. 
After this operation, 97.3 MB of additional disk space will be used. 

一旦所有這些庫安裝,安裝包的PyPI將正確安裝。

PyPi僅適用於Python包(以及這些包的Python特定依賴項)。對於任何外部要求;您需要在安裝文檔中指定這些文件,或者在系統上提供這些文件,以便安裝過程可以成功。

+0

感謝您的回答,這對我來說很明顯,我的問題是如何在設置腳本中包含'apt-get'? –

+0

你不能。它僅適用於PyPi提供的軟件包。您可以創建一個自定義shell腳本來安裝這些軟件包。 –

0

嘗試使用這個修改的腳本:

from setuptools import setup 

setup( 
    name = 'SomeName', 
    version = '0.1', 
    packages=find_packages(), 
    author = 'Some Author', 
    maintainer = 'Some', 
    maintainer_email = '[email protected]', 
    description = '', 
    url = 'www.some.com', 
    install_requires = ['envisage', 
         'pyface', 
         'apptools', 
         'chaco', 
         'traits', 
         'traitsui', 
         'mysql-connector-python', 
         'pysnmp4', 
         'pyasn1', 
         'm2crypto', 
         'netifaces' 

         ], 
) 
+0

我也試過這個,同樣的錯誤... –

+0

這不會工作,因爲那些不是PyPi包。 –

相關問題