You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

pip安装hashnode-py时未自动安装依赖问题求助

解决pip安装hashnode-py时未自动安装依赖的问题

问题根源

你的情况大概率是以下两个原因之一:

  • requirements.txt 未被包含在分发包中,导致安装阶段setup.py无法读取到依赖内容
  • setup.py的依赖读取逻辑存在路径错误,或是未将读取到的依赖正确传递给install_requires参数

具体修复步骤

1. 确保requirements.txt被打包包含

在项目根目录创建MANIFEST.in文件,写入以下内容:

include requirements.txt

这个文件会告诉setuptools在打包时将requirements.txt纳入分发包,否则安装环境中不会存在该文件,setup.py自然无法读取依赖列表。

2. 修正setup.py的依赖处理逻辑

打开setup.py,确保依赖读取代码正确,并将结果赋值给install_requires参数,示例写法如下:

from setuptools import setup

def load_requirements():
    with open('requirements.txt', 'r') as f:
        # 过滤空行和注释行
        return [line.strip() for line in f if line.strip() and not line.startswith('#')]

setup(
    name='hashnode-py',
    # 保留你的其他配置参数
    install_requires=load_requirements(),
)

如果requirements.txt里有版本限制(比如gql>=3.0.0),这种写法完全兼容。

3. 重新打包并验证

执行命令重新生成分发包:

python setup.py sdist bdist_wheel

然后用本地包测试安装,确认依赖是否自动安装:

pip install dist/hashnode_py-*.tar.gz

额外优化方案(可选)

现在Python打包更推荐用pyproject.toml直接声明依赖,避免路径和打包包含的问题。在项目根目录创建pyproject.toml,写入:

[project]
name = "hashnode-py"
# 补充你的其他元信息(版本、作者等)
dependencies = [
    "gql",
    "requests"
]

这种方式更简洁,也能避免读取文件的潜在问题。

内容的提问来源于stack exchange,提问作者talaat mohamed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 14:37:07