python - Setup.py 安装需要本地包
问题描述
我正在寻找my-package
使用setuptools
. my-package
具有本地依赖性,utils
. 我的文件结构如下:
parent/
my-package/
my-package/
setup.py
utils/
utils/
setup.py
我正在寻找使用以下内容安装本地依赖项:
from setuptools import setup
import os
setup(
name='my-package',
version='1.0',
packages=['my-package'],
install_requires=[
# location to your my-package project directory
"file:\\" + os.path.join(os.path.dirname(os.getcwd()), 'utils#egg=utils-1.0')
]
)
不幸的是,出现以下错误:
ERROR: Command errored out with exit status 1:
command: /path/to/python/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/my-package/setup.py'"'"'; __file__='"'"'/home/my-package/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info
cwd: /home/my-package/
Complete output (1 lines):
error in my-package setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'://home/'"
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
我在这里尝试了解决方案,但没有运气。任何帮助是极大的赞赏。
解决方案
dependency_links
已弃用。这是一个丑陋的黑客,一个非常糟糕的做法。我不建议你这样做。
此 hack 旨在安装为python setup.py install
,现在也已弃用。如果您使用pip安装,那么很可能这将不起作用。
一般来说,相对路径依赖在 Python 打包中总是一个坏主意,我建议你用不同的方式解决它。
话虽如此,这样的事情可能会起作用,或者至少在过去的某个时候可能会起作用:
.
├── One
│ ├── one
│ │ └── __init__.py
│ └── setup.py
└── Two
├── setup.py
└── two
└── __init__.py
One/setup.py
#!/usr/bin/env python3
import setuptools
import pathlib
TWO_PATH = pathlib.Path(__file__).resolve().parent.parent.joinpath('Two')
setuptools.setup(
name='One',
version='1.2.3',
packages=['one'],
install_requires=['Two'],
dependency_links=[
'file://{}#egg=Two-1.2.3'.format(TWO_PATH),
],
)
推荐阅读
- python - 如何修复 NameError:运行 python 脚本时未定义名称“作者”
- powershell - PowerShell 用户输入、菜单、子菜单、
- protractor - 量角器在配置中有 2 个框架
- android - Picasso 不将 url 加载到 ImageView 传递值时抛出构造函数
- sql - 创建了一个包含主键列和两个外键列的连接表,而不是拉入数据
- c# - 无法创建目录:System.UnauthorizedAccessException 错误
- macos - 如何在 macOS 上获取 awk 版本?
- r - 使用 r 中其他两列的 group_by 计算行数
- haskell - 如何修复haskell中的“函数中的非详尽模式”错误?
- java - 如何删除JPanel内图像和文本之间的空白?