我刚刚使用 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'
],
)
最佳答案
从 apt 存储库安装,下载的二进制文件已使用所需的系统库构建。如果没有,apt 管理器会确保所有系统库也已安装。使用 setuptools(pip 或 easy_install)安装仅获取 python 要求;而不是构建/系统要求。
在您的情况下,错误是错误:未找到X11库。
这意味着X11的构建 header 在您的系统中不可用。解决这个问题的一个简单方法是告诉 apt 仅下载并安装包的依赖项(而不是包本身)。这将确保当您使用 pip 或 easy_install 时,Python 会找到它需要的一切。
例如,psycopg2
是 Postgresql 的 Python 库。要构建它,您需要 postgresql 支持库( header 和文件)。 PyPi 不提供这些。 debian 软件包 python-psycopg2
将正确安装所有外部需求。现在,如果我想在虚拟环境中安装 psycopg2,我首先需要确保我的系统具有构建包的所有外部要求,因此我运行以下命令:
sudo apt-get build-dep python-pyscopg2
这只会安装依赖项(所有支持 header ),以便我稍后可以手动安装它。
在您的情况下,您应该运行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 特定依赖项)。对于任何外部要求;您需要在安装文档中指定这些内容或让它们在系统上可用,以便安装过程能够成功。
关于python - 如何在安装程序中安装 PyPi 的 Ubuntu 软件包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13816605/