标签: distutils

Python:pip在root目录中安装子包

我有这样的结构:

setup.py
package
    __init__.py
    sub_package
        ___init__.py
    sub_package2
        __init__.py
Run Code Online (Sandbox Code Playgroud)

如果我通过setup.py install安装软件包,那么它可以正常工作(通过将整个软件包复制到site-packages目录):

site_packages
    package
        sub_package
        sub_package2
Run Code Online (Sandbox Code Playgroud)

但是如果我运行pip install package,那么pip会将每个子包安装为独立的包:

site-packages
    package
    sub_package
    sub_package2
Run Code Online (Sandbox Code Playgroud)

我怎么能避免这个?我使用setuptools中的find_packages()来指定包.

python distutils pip setuptools

4
推荐指数
1
解决办法
1993
查看次数

distutils"不是常规文件 - skipped"

我有一个非常简单的设置:

from distutils.core import setup

setup(name='myscripts',
      description='my scripts',
      author='Ago',
      author_email='blah',
      version='0.1',
      packages=['myscripts']
      )

myscripts文件夹包含大约10个python文件.如果我只执行我的main.py文件(可执行文件,它使用这些myscripts文件),Everthing工作正常.现在我尝试做: python setup.py sdist

但我得到:

running sdist
warning: sdist: missing required meta-data: url
reading manifest file 'MANIFEST'
creating myscripts-0.1
making hard links in myscripts-0.1...
'file1.py' not a regular file -- skipping
hard linking setup.py -> myscripts-0.1
'file2.py' not a regular file -- skipping
tar -cf dist/myscripts-0.1.tar myscripts-0.1
gzip -f9 dist/myscripts-0.1.tar
removing 'myscripts-0.1' (and everything under it)

文件file1.pyfile2.py其他文件一样规则.有什么建议?

python installation distutils

4
推荐指数
1
解决办法
2320
查看次数

使用distutils构建Python扩展模块

我正在使用distutils来构建一个用C++编写的Python扩展模块.我遇到的问题是,为了编译扩展模块,我需要链接某个共享库.这需要设置额外的编译器标志.所以,我搜索了Python文档,发现了对象的extra_compile_args属性Extension.所以我尝试了以下方法:

from distutils.core import setup, Extension

module = Extension('test', sources = ['test.cpp'])
module.extra_compile_args = ['--std=c++0x', '-l mylib'];
setup(name = 'test', version = '1.0', ext_modules = [module])
Run Code Online (Sandbox Code Playgroud)

这似乎是编译的,除非我在Python中导入我的模块时ImportError由于未定义的符号而引发异常.所以,显然图书馆没有正确链接.所以我尝试编写一个与共享库链接的丢弃C++程序,它运行正常.然后我意识到一些非常奇怪的事情distutils,因为如果我添加一个链接到伪造库名称的编译参数,distutils只会编译所有内容而没有问题:

module.extra_compile_args = ['--std=c++0x', '-l some_fake_library'];
Run Code Online (Sandbox Code Playgroud)

当我运行时setup.py build,构建运行没有错误!

那么,这里发生了什么?如何编译需要链接到共享库的扩展模块?

c++ python gcc distutils

4
推荐指数
1
解决办法
4041
查看次数

distutils可以在不安装的情况下执行依赖性检查吗?

是否有可能让distutils运行python模块依赖性分析(并可能安装缺少的模块)而不实际安装python模块?我想象一个命令如下:

./setup.py check-dependencies
Run Code Online (Sandbox Code Playgroud)

如果目标系统上缺少任何相关模块,则会报告.

python distutils setup.py

4
推荐指数
2
解决办法
3219
查看次数

Cython和distutils

我想使用Cython将多个.pyx文件转换为可执行包(.DLL).

如何通过distutils从多个.pyx创建单个Windows DLL?

使用的样本:

sub1.pyx:

cimport sub1

class A():
    def test(self, val):
        print "A", val
Run Code Online (Sandbox Code Playgroud)

sub1.pxd:

cdef class A:
    cpdef test(self,val)
Run Code Online (Sandbox Code Playgroud)

sub2.pyx:

cimport sub2

class B():
    def test(self):
        return 5
Run Code Online (Sandbox Code Playgroud)

sub2.pxd:

cdef class B:
    cpdef test(self)
Run Code Online (Sandbox Code Playgroud)

init .py:

cimport sub1
cimport sub2

import sub1
import sub2
Run Code Online (Sandbox Code Playgroud)

setup.py:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension("sub", ["__init__.pyx", "sub1.pyx", "sub2.pyx"])]

setup(
  name = 'Hello world app',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules
)
Run Code Online (Sandbox Code Playgroud)

错误: …

python distutils cython

4
推荐指数
1
解决办法
1794
查看次数

将输出文件添加到 Python 扩展

我已经定义了一个自定义build_ext来构建一个时髦的扩展,我试图使 pip 友好。以下是我正在做的修剪版本。

foo_ext = Extension(
  name='foo/_foo',
  sources=foo_sources,
)

class MyBuildExt(build_ext):
  def build_extension(self, ext):
    # This standalone script builds the __init__.py file 
    #  and some .h files for the extension
    check_call(['python', 'build_init_file.py'])

    # Now that we've created all the init and .h code
    #  build the C/C++ extension using setuptools/distutils
    build_ext.build_extension(self, ext)

    # Include the generated __init__.py in the build directory 
    #  which is something like `build/lib.linux-x86/foo/`.  
    #  How can I get setuptools/distutils to install the 
    #  generated …
Run Code Online (Sandbox Code Playgroud)

python distutils pip setuptools python-extensions

4
推荐指数
1
解决办法
1139
查看次数

使用WiX或Inno Setup捆绑几个MSI文件的安装

我使用cx-freeze为Python应用程序创建MSI安装程序.我们称之为应用程序"A".它取决于另一个应用程序"B".我希望我的"A"安装程序包含并运行"B"的MSI安装程序.如何使用Inno Setup或WiX工具集创建引导/链接安装程序?

windows-installer distutils inno-setup wix cx-freeze

4
推荐指数
1
解决办法
3242
查看次数

为什么我在使用 distutils 时会创建一个 egg-info 文件?

下面是我的 setup.py。我的代码中没有使用 setuptools 中的任何内容,并且我的项目没有外部依赖项

#!/usr/bin/env python

from distutils.core import setup

setup(name='dots',
        ...
        packages=['dots','dots.configs','dots.management','dots.utils','dots.test'],
        scripts=['dots/dots.py']
        )
Run Code Online (Sandbox Code Playgroud)

当我运行时python setup.py install,我得到以下信息

running install
running build
running build_py
running build_scripts
running install_lib
running install_scripts
changing mode of /Users/kevinlin/.virtualenvs/p-dots/bin/dots.py to 755
running install_egg_info                                                                                <- why?
Removing /Users/kevinlin/.virtualenvs/p-dots/lib/python2.7/site-packages/dots-0.1-py2.7.egg-info
Writing /Users/kevinlin/.virtualenvs/p-dots/lib/python2.7/site-packages/dots-0.1-py2.7.egg-info
(p-dots)Kevins-MacBook-Pro-2% python setup.py install
running install
running build
running build_py
running build_scripts
running install_lib
running install_scripts
changing mode of /Users/kevinlin/.virtualenvs/p-dots/bin/dots.py to 755
running install_egg_info
Removing /Users/kevinlin/.virtualenvs/p-dots/lib/python2.7/site-packages/dots-0.1-py2.7.egg-info
Writing /Users/kevinlin/.virtualenvs/p-dots/lib/python2.7/site-packages/dots-0.1-py2.7.egg-info
Run Code Online (Sandbox Code Playgroud)

我注意到安装了一个 .egg-info 文件

ls -dl /Users/kevinlin/.virtualenvs/p-dots/lib/python2.7/site-packages/dots* …
Run Code Online (Sandbox Code Playgroud)

python distutils setuptools virtualenvwrapper

4
推荐指数
1
解决办法
2428
查看次数

如何覆盖 PBR 中的要求?

我正在尝试使用 PBR(Python 构建合理性)打包我的 Python 代码。它通过一组约定为您生成需求元数据。

需求文件按该顺序尝试(N 是用于安装包的 Python 主要版本号):

需求-pyN.txt

工具/pip-requires-py3

要求.txt

工具/pip-需要

在我的目录中,我需要有一个requirements.txtfor 另一个约定,其中一个 Docker 容器需要它,该容器具有与我发布的目标不同的一组要求。我想在这个项目中同时保留 Docker 镜像生成和 python 包构建,因为它们有公共文件。

我怎么能指定一个要求,比如requirements-pbr.txt并覆盖 PBR 将引入的事实requirements.txt

python distutils build setup.py

4
推荐指数
1
解决办法
640
查看次数

仅在setup.py中可能时编译可选的cython扩展

我有一个完全在python中实现的python模块。(出于便携性原因。)

cython模块中已复制了一小部分的实现。在可能的情况下提高性能。

我知道如何使用来安装.ccython创建的模块distutils。但是,如果一台机器没有安装编译器,我怀疑即使该模块在纯python模式下仍然可用,安装也会失败。

有没有办法编译该.c模块(如果可能的话),但无法正常运行,如果无法编译,则在没有该模块的情况下进行安装?

python distutils cython setup.py distutils2

4
推荐指数
1
解决办法
973
查看次数