我正在为 C++ 库编写 Cython 包装器,我想将其作为 Python 包分发。我已经想出了我的包的虚拟版本,如下所示(完整源代码在这里)。
\n\n$ tree\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bogus.pyx\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 inc\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 bogus.hpp\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 setup.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 src\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 bogus.cpp\n$\n$ cat inc/bogus.hpp \n#ifndef BOGUS\n#define BOGUS\n\nclass bogus\n{\nprotected:\n int data;\n\npublic:\n bogus();\n int get_double(int value);\n};\n\n#endif\n$\n$ cat src/bogus.cpp \n#include "bogus.hpp"\n\nbogus::bogus() : data(0)\n{\n\n}\n\nint bogus::get_double(int value)\n{\n data = value * 2;\n return data;\n}\n$ cat bogus.pyx \n# distutils: language = c++\n# distutils: sources = src/bogus.cpp\n# cython: c_string_type=str, c_string_encoding=ascii\n\ncdef extern from \'bogus.hpp\':\n cdef cppclass bogus:\n bogus() except +\n int get_double(int value)\n\ncdef class Bogus:\n cdef bogus b\n def get_double(self, …Run Code Online (Sandbox Code Playgroud) 请在标记为重复之前,我尝试了一系列解决方案,包括此处的一个 ,但没有运气
我创建了一个简单的工具来完成一些任务,并且能够成功地将其打包。
当尝试安装它时,我在使用时获得了所需的效果python setup.py install,但pip install package_name只安装了软件包,但没有安装后脚本。
这是我的代码的一部分;
安装程序.py
from distutils import setup
from app.scripts import *
setup(
#Application name
name = "my-app-name",
version = "my-app-version",
author = "my-name",
author_email = "my-email",
packages = ['app'],
include_package_data = True,
license = 'MIT',
url = "https://my-url",
description = "description",
install_requires = ["flake8"],
cmdclass = {
"install":Post_install
}
)
Run Code Online (Sandbox Code Playgroud)
脚本.py
from distutils.command.install import install
import os
class Post_install(install):
@staticmethod
def func():
return True
def run(self): …Run Code Online (Sandbox Code Playgroud) 有没有办法在使用时指定可选依赖项python setup.py develop?
例如,假设我有这个包:
pip install openwisp-utils[users]
Run Code Online (Sandbox Code Playgroud)
如何通过告诉 setuptools 安装 中列出的可选依赖项来安装openwisp-utilsextra_requires['users']进行开发?
假设有人想要打包一个依赖于 C++ boost 库的 Python (Cython) 库。
配置的最佳方法是什么setup.py,以便正确地通知用户需要安装 boost 库(即apt-get install libboost-dev在 Ubuntu 等其他操作系统中)?或者将 boost 库包含在 python 包分发中是更好的做法吗?
我有一套一起开发并捆绑到一个分发包中的软件包。
为了便于讨论,我们假设我有充分的理由按以下方式组织我的 python 发行包:
SpanishInqProject/
|---SpanishInq/
| |- weapons/
| | |- __init__.py
| | |- fear.py
| | |- surprise.py
| |- expectations/
| | |- __init__.py
| | |- noone.py
| |- characters/
| |- __init__.py
| |- biggles.py
| |- cardinal.py
|- tests/
|- setup.py
|- spanish_inq.pth
Run Code Online (Sandbox Code Playgroud)
spanish_inq.pth我已经添加了要添加SpanishInq到 的路径配置文件sys.path,因此我可以直接导入weapons, .etc 。
我希望能够使用 setuptools 构建轮子并在目录中安装 pip install ,但weapons不创建包或命名空间。expectationscharactersSpanishInqSpanishInq
我的设置.py:
from setuptools import setup, …Run Code Online (Sandbox Code Playgroud) 我想通过在setup.py.
我已经尝试通过以下方式指定在哪里查找依赖项dependency_links:
setup(
...
install_requires=["foo==1.0"],
dependency_links=["https://my.private.pypi/"],
...
)
Run Code Online (Sandbox Code Playgroud)
我还尝试在以下位置定义整个 URL dependency_links:
setup(
...
install_requires=[],
dependency_links=["https://my.private.pypi/foo/foo-1.0.tar.gz"],
...
)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试安装时python setup.py install,它们都不适合我。
有谁能够帮助我?
编辑:
使用第一段代码我得到了这个错误:
...
Installed .../test-1.0.0-py3.7.egg
Processing dependencies for test==1.0.0
Searching for foo==1.0
Reading https://my.private.pypi/
Reading https://pypi.org/simple/foo/
Couldn't find index page for 'foo' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
No local packages or working download links found for foo==1.0
error: Could not find suitable distribution …Run Code Online (Sandbox Code Playgroud) 我想使用诗歌工具创建一个空(元)包,主要是为了简化将依赖项列表组合在一起的过程。如果我按如下方式创建 project.toml:
[build-system]
requires = ["poetry"]
[tool.poetry]
name = "metapackage"
version = "1.0.0"
description = "My empty metapackage"
authors = ["Me"]
license = "MIT"
[tool.poetry.dependencies]
numpy = "*"
Run Code Online (Sandbox Code Playgroud)
然后执行poetry build,出现错误:
$ mkdir -p metapackage
$ python -m poetry build --no-interaction --format wheel -vvvUsing virtualenv: /Users/duncan/opt/miniconda3/envs/py37
Building metapackage (1.0.0)
[ValueError]
metapackage is not a package.
Traceback (most recent call last):
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/clikit/console_application.py", line 131, in run
status_code = command.handle(parsed_args, io)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/clikit/api/command/command.py", line 120, in handle
status_code = self._do_handle(args, …Run Code Online (Sandbox Code Playgroud) 我有一个自己编写的自定义包,名为 deblurrer,它是一堆用于训练神经网络的脚本。
在 Google Colab 中,我成功克隆了我的存储库,我拥有执行 setup.py 模块和安装 deblurrer 1.0.0 所需的所有内容。当我在我的电脑本地安装 deblurrer 时,一切都按预期工作,但是当我尝试!python setup.py install在 Colab 中运行时,没有安装任何内容,事实上,输出表明一切都很好,但我无法导入包。在两个单独的 Colab 单元中执行下一个代码以重现该问题:
# Cell 01
# Executes the cell in bash mode
%%bash
git clone https://github.com/ElPapi42/deep-deblurring
python deep-deblurring/setup.py install
Run Code Online (Sandbox Code Playgroud)
# Cell 02
import deblurrer
Run Code Online (Sandbox Code Playgroud)
如您所见,安装按预期运行,但导入时:ModuleNotFoundError: No module named 'deblurrer'
有什么问题吗?
python jupyter-notebook python-packaging google-colaboratory
我正在尝试编写脚本,它应该使用 Portage API。但是 Portage python 包在 PyPi 中不可用,但即使可用也没有任何意义,因为它应该从某些具有包数据库和配置的配置系统中使用。
我尝试编写以下丑陋的代码:
[tool.poetry.dependencies]
python = "^3.6"
click = "^7.0-r1"
portage = [
{ markers = "python_version ~= '3.6' and sys_platform == 'linux'", path = "/usr/lib64/python3.6/site-packages/portage/" },
{ markers = "python_version ~= '3.7' and sys_platform == 'linux'", path = "/usr/lib64/python3.7/site-packages/portage/" },
{ markers = "python_version ~= '3.8' and sys_platform == 'linux'", path = "/usr/lib64/python3.8/site-packages/portage/" },
{ markers = "python_version ~= '3.9' and sys_platform == 'linux'", path = "/usr/lib64/python3.9/site-packages/portage/" }
]
Run Code Online (Sandbox Code Playgroud)
但这不起作用。Poetry 不会将路径目录中的代码视为 …
我完成了将包上传到https://test.pypi.org/的教程,并且成功地做到了这一点。
但是,会在目录中$python setup.py sdist bdist_wheel生成一个.whl文件和一个tar.gz文件dist/。twine允许仅上传.whl或tar.gz文件或两者。我看到https://pypi.org/上的许多存储库都上传了这两种格式。
我想了解什么是最佳实践。一种格式优于另一种格式吗?如果.whl文件足以分发我的代码,我tar.gz也应该上传文件吗?或者还有什么我在这里完全想念的吗?
python-packaging ×10
python ×9
setuptools ×4
pypi ×3
boost ×1
cython ×1
distutils ×1
gentoo ×1
openwisp ×1
packaging ×1
pip ×1
pth ×1
python-2.7 ×1
python-3.x ×1
setup.py ×1
twine ×1