1

我刚刚用 setuptool 制作了一个 Python 包,但是我遇到了一个问题,如果我从 Ubuntu 存储库中预安装所有东西,它的工作,但是当我使用 PyPi 时,安装失败,因为在 PyPi 上只包含源并且它必须是编译,所以安装过程中有很多错误源。在安装包期间如何安装 Ubuntu 包?我的想法是subprocess,有没有更好的方法?

已编辑

错误信息

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 = 'some@email.com',
    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'

                        ],
 )
4

2 回答 2

1

从 apt 存储库安装下载的二进制文件已经使用所需的系统库构建。如果没有,apt 管理器会确保所有系统库也已安装。使用 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 的依赖项)。对于任何外部要求;您需要在安装文档中指定它们或让它们在系统上可用,以便安装过程能够成功。

于 2012-12-11T09:27:11.067 回答
0

Try using this modified script:

from setuptools import setup

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

                        ],
 )
于 2012-12-11T09:23:12.330 回答