【问题标题】:How does one install PyTorch and related tools from within the setup.py install_requires list?如何从 setup.py install_requires 列表中安装 PyTorch 和相关工具?
【发布时间】:2022-01-14 15:17:01
【问题描述】:

我在更换笔记本电脑后尝试在my library ultimate-utils 上测试pip install -e .,但我不断收到此类错误:

(uutils_env) brandomiranda~/ultimate-utils ❯ pip install -e .                      
Obtaining file:///Users/brandomiranda/ultimate-utils
  Preparing metadata (setup.py) ... done
ERROR: Could not find a version that satisfies the requirement torchvision==0.10.1 (from ultimate-utils) (from versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.2.post2, 0.2.2.post3)
ERROR: No matching distribution found for torchvision==0.10.1

(uutils_env) brandomiranda~/ultimate-utils ❯ pip install -e .
Obtaining file:///Users/brandomiranda/ultimate-utils
  Preparing metadata (setup.py) ... done
ERROR: Could not find a version that satisfies the requirement torch==1.9.1 (from ultimate-utils) (from versions: none)
ERROR: No matching distribution found for torch==1.9.1

由于某种原因,它似乎停止安装任何与 pytorch 相关的东西。

我尝试更新 pip 和 conda,但没有成功。我做到了:

pip install --upgrade pip
conda update conda
conda update conda-build
conda update -n base -c defaults conda
conda update --name base conda
conda update --all
conda install anaconda

但似乎没有一个工作。

我的 setup.py 如下所示:

"""
conda create -n uutils_env python=3.9
conda activate uutils_env
conda remove --all --name uutils_env
rm -rf /Users/brando/anaconda3/envs/uutils_env

pip install -e ~/ultimate-utils/ultimate-utils-proj-src/

pip install ultimate-utils

To test it:
python -c "import uutils; uutils.hello()"
python -c "import uutils; uutils.torch_uu.hello()"

python -c "import uutils; uutils.torch_uu.gpu_test_torch_any_device()"
python -c "import uutils; uutils.torch_uu.gpu_test()"

PyTorch:
    basing the torch install from the pytorch website as of this writing: https://pytorch.org/get-started/locally/
    pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

refs:
    - setup tools: https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#using-find-or-find-packages
"""
from setuptools import setup
from setuptools import find_packages
import os

# import pathlib

here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
    long_description = f.read()

setup(
    name='ultimate-utils',  # project name
    version='0.5.3',
    description="Brando's ultimate utils for science, machine learning and AI",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url='https://github.com/brando90/ultimate-utils',
    author='Brando Miranda',
    author_email='brandojazz@gmail.com',
    python_requires='>=3.9.0',
    license='MIT',
    package_dir={'': 'ultimate-utils-proj-src'},
    packages=find_packages('ultimate-utils-proj-src'),  # imports all modules/folders with  __init__.py & python files

    # for pytorch see doc string at the top of file
    install_requires=[
        # 'torch==1.9.1',
        'torchvision==0.10.1',
        'torchaudio==0.9.1',
        'dill',
        'networkx>=2.5',
        'scipy',
        'scikit-learn',
        'lark-parser',
        'torchtext==0.10.1',
        'tensorboard',
        'pandas',
        'progressbar2',
        'transformers',
        'requests',
        'aiohttp',
        'numpy',
        'plotly',
        'wandb',
        'matplotlib',
        # 'seaborn'

        # 'pygraphviz'  # removing because it requires user to install graphviz and gives other issues
    ]
)

目录结构很简单:

我该如何解决这个问题以及什么不起作用?

我试图避免在外部运行 pip 命令,例如:

conda install pytorch torchvision torchaudio -c pytorch

至少对于我本地笔记本电脑中的 cpu 而言...如果我可以使用标志自动安装 gpu 可能会很好,但对于未来的工作...

顺便说一句,如果可能的话,我更喜欢没有 requirements.txt 解决方案,但也要发布这些解决方案,以防其他任何方法都不起作用。


这是针对英特尔 mac 2013 的,但我将在 2 个月内获得最大 m1,因此也欢迎这些答案!


仍然失败:

(uutils_env) brandomiranda~/ultimate-utils ❯ pip install -e .
Obtaining file:///Users/brandomiranda/ultimate-utils
  Preparing metadata (setup.py) ... done
ERROR: Could not find a version that satisfies the requirement torch<1.10.0,>=1.4.0 (from ultimate-utils) (from versions: none)
ERROR: No matching distribution found for torch<1.10.0,>=1.4.0

我试过的相关资源:

【问题讨论】:

  • 命令 conda remove --all --name uutils_env 正在从环境中删除 Python。这可能会让python 在其他地方解决,甚至可能是系统级别的。该 Python 版本可能没有您指定的 PyTorch 版本。
  • @merv 我很困惑。你为什么要告诉我这个……?
  • 这是setup.py 文件的注释部分的第三行,我认为这是您设置uutils_env 的方式。在 Mac 上,pip 将对应于/usr/bin/python,即 Python v2.7。这可以解释为什么找不到兼容的 torchtorchvision 包。也许在问题中包含来自which python 的输出。
  • @merv 我通过conda create -n uutils_env python=3.9 然后pip install -e . 进行设置。另一件事并没有说按那个顺序运行它,它们只是随机命令。它也不在自述文件中。抱歉,如果这令人困惑。
  • 好的,但是您还应该在创建环境时安装pip,即conda create -n uutils_env python=3.9 pip。否则,pip 仍然可以在环境之外解析。

标签: python pip pytorch anaconda conda


【解决方案1】:

请参阅此Why is python using 3.8.1 and 3.9, then fail to install packages (ERROR: Package pkg requires a different Python: 3.8.1 not in '>=3.9.0')? 以获得更完整的答案,但总结是 pytorch 现在似乎无法在 python 3.10 上可靠运行,因此我使用 3.9 创建了一个 env,然后它安装了我需要的东西。

【讨论】:

    猜你喜欢
    • 2020-06-10
    • 2016-05-06
    • 2018-04-05
    • 2021-06-18
    • 1970-01-01
    • 2016-10-08
    • 2011-08-30
    • 2019-12-10
    • 2021-10-26
    相关资源
    最近更新 更多