Python setup.py 错误:“install_requires”必须是字符串或字符串列表

问题描述 投票:0回答:1

我正在尝试在这里构建 Transformer Grammars 代码:https://github.com/google-deepmind/transformer_grammars/tree/main

我正在运行 Google Cloud 深度学习 VM、N1 实例、TensorFlow 2.10(CUDA 11.3、Python 3.7)。

这是我尝试运行的

install.sh
文件的内容:

set verbose
set -o errexit

rm -rf .dependencies
mkdir .dependencies
cd .dependencies
git clone -b 20220623.1 https://github.com/abseil/abseil-cpp.git
git clone -b 3.4.0 https://gitlab.com/libeigen/eigen.git
git clone -b v2.10.2 https://github.com/pybind/pybind11.git

sudo apt-get install cmake build-essential pkg-config libgoogle-perftools-dev
git clone -b v0.1.97 https://github.com/google/sentencepiece.git
cd sentencepiece
mkdir build
cd build
make -j
sudo make install
sudo ldconfig -v

cd ../../..
pip install --require-hashes -r requirements.txt
pip install -e . --no-deps --no-index

rm -rf .dependencies

错误文本如下:

error in transformer_grammars setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'\\'"

在setup.py中的

setup()
命令中,与
install_requires
相关的代码为

install_requires=dependencies

dependencies
得到为

with open("requirements.txt", "r") as f:
     dependencies = list(map(lambda x: x.strip(), f.readlines()))

值得注意的是,这是在

requirements.txt
的底部:

# WARNING: The following packages were not pinned, but pip requires them to be
# pinned when the requirements file includes hashes. Consider using the --allow-unsafe flag.
# setuptools

我真的不知道这意味着什么,但假设它可能相关,因为我见过的其他帖子有与此类似的错误涉及 setuptools。

我尝试过的事情都无济于事:

  • 升级点
  • 升级设置工具
  • 恢复到旧版本的 setuptools (39.1.0)
  • 联系 DeepMind 相关人员

非常感谢任何帮助。

python google-cloud-platform deep-learning pip transformer-model
1个回答
0
投票

该问题很可能是由于您的requirements.txt 文件中的注释或其他额外信息造成的。确保文件格式正确,然后尝试以下操作:

def parse_req_line(s: str) -> str:
    s = s.strip().replace("\n", "")
    return "" if len(s) < 2 or s.startswith("#") else s

with open("requirements.txt", "r") as f:
     dependencies = [d for l in f.readlines() if (d := parse_req_line(l))]
© www.soinside.com 2019 - 2024. All rights reserved.