无法在 virtualenv 中安装 python 包错误:命令“x86_64-linux-gnu-gcc”失败,退出状态为 1

发布于 2025-01-11 04:42:47 字数 5715 浏览 4 评论 0原文

我在windows子系统ubuntu 20.04.3中使用python,我创建了一个虚拟环境并安装了python 3.7(ubuntu 系统有python 3.8),我需要安装python包然而,在我运行 pip install torch-scatter -f 之后,torch-sparse https://data.pyg.org/whl/torch-1.4.0+cpu.html,我遇到了以下错误:

   /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/aten_interned_strings.h:1001:9: note: ‘c10::attr::value’ declared here
     1001 | _(attr, value) \
          |         ^~~~~
    /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:373:35: note: in definition of macro ‘DEFINE_SYMBOL’
      373 |   namespace ns { constexpr Symbol s(static_cast<unique_t>(_keys::ns##_##s)); }
          |                                   ^
    /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:204:3: note: in expansion of macro ‘FORALL_ATTR_BASE_SYMBOLS’
      204 |   FORALL_ATTR_BASE_SYMBOLS(_)        \
          |   ^~~~~~~~~~~~~~~~~~~~~~~~
    /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:374:1: note: in expansion of macro ‘FORALL_NS_SYMBOLS’
      374 | FORALL_NS_SYMBOLS(DEFINE_SYMBOL)
          | ^~~~~~~~~~~~~~~~~
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    ---------------------------------------- ERROR: Command errored out with exit status 1: /home/alva/python/foo-3.7/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bd2qx3dj/torch-sparse/setup.py'"'"';
__file__='"'"'/tmp/pip-install-bd2qx3dj/torch-sparse/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-ppnxm3yh/install-record.txt
--single-version-externally-managed --compile --install-headers /home/alva/python/foo-3.7/include/site/python3.7/torch-sparse Check the logs for full command output. WARNING: You are using pip version
20.1.1; however, version 22.0.3 is available. You should consider upgrading via the '/home/alva/python/foo-3.7/bin/python3.7 -m pip install --upgrade pip' command.

并且

 In file included from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/Dimname.h:5,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/NamedTensor.h:4,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/TensorBody.h:20,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/Tensor.h:11,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/Context.h:4,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/ATen.h:5,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/types.h:3,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/data.h:3,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/all.h:4,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/extension.h:4,
                   from csrc/cpu/convert_cpu.h:3,
                   from csrc/cpu/convert_cpu.cpp:1:   /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/aten_interned_strings.h:1001:9: note: ‘c10::attr::value’ declared here    1001 | _(attr, value) \
        |         ^~~~~   /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:373:35: note: in definition of macro ‘DEFINE_SYMBOL’
    373 |   namespace ns { constexpr Symbol s(static_cast<unique_t>(_keys::ns##_##s)); }
        |                                   ^   /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:204:3: note: in expansion of macro ‘FORALL_ATTR_BASE_SYMBOLS’
    204 |   FORALL_ATTR_BASE_SYMBOLS(_)        \
        |   ^~~~~~~~~~~~~~~~~~~~~~~~   /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:374:1: note: in expansion of macro ‘FORALL_NS_SYMBOLS’
    374 | FORALL_NS_SYMBOLS(DEFINE_SYMBOL)
        | ^~~~~~~~~~~~~~~~~   error: command 'x86_64-linux-gnu-gcc' failed with exit status 1   ----------------------------------------   ERROR: Failed building wheel for torch-sparse

我尝试了代码

sudo apt-get install python3.7-dev

sudo apt-get install libpq-dev python-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libffi-dev

sudo apt-get install python3.7-dev

sudo apt install build-essential

pip install torch-sparse -f https://data.pyg.org/whl/torch-1.4.0/torch_sparse-0.5.1+cpu-cp37-cp37m-linux_x86_64.whl

但我仍然​​遇到相同的错误。我有 torch 1.4.0+cpu,但我不认为 torch 版本有问题。

我怎样才能摆脱这个错误?预先非常感谢。

I am using python in windows subsystem ubuntu 20.04.3, I created a virtual environment and installed python 3.7 (ubuntu system has python 3.8), I need to install the python package torch-sparse, however, after I ran pip install torch-scatter -f https://data.pyg.org/whl/torch-1.4.0+cpu.html, I had following error:

   /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/aten_interned_strings.h:1001:9: note: ‘c10::attr::value’ declared here
     1001 | _(attr, value) \
          |         ^~~~~
    /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:373:35: note: in definition of macro ‘DEFINE_SYMBOL’
      373 |   namespace ns { constexpr Symbol s(static_cast<unique_t>(_keys::ns##_##s)); }
          |                                   ^
    /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:204:3: note: in expansion of macro ‘FORALL_ATTR_BASE_SYMBOLS’
      204 |   FORALL_ATTR_BASE_SYMBOLS(_)        \
          |   ^~~~~~~~~~~~~~~~~~~~~~~~
    /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:374:1: note: in expansion of macro ‘FORALL_NS_SYMBOLS’
      374 | FORALL_NS_SYMBOLS(DEFINE_SYMBOL)
          | ^~~~~~~~~~~~~~~~~
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    ---------------------------------------- ERROR: Command errored out with exit status 1: /home/alva/python/foo-3.7/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bd2qx3dj/torch-sparse/setup.py'"'"';
__file__='"'"'/tmp/pip-install-bd2qx3dj/torch-sparse/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-ppnxm3yh/install-record.txt
--single-version-externally-managed --compile --install-headers /home/alva/python/foo-3.7/include/site/python3.7/torch-sparse Check the logs for full command output. WARNING: You are using pip version
20.1.1; however, version 22.0.3 is available. You should consider upgrading via the '/home/alva/python/foo-3.7/bin/python3.7 -m pip install --upgrade pip' command.

and

 In file included from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/Dimname.h:5,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/NamedTensor.h:4,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/TensorBody.h:20,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/Tensor.h:11,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/Context.h:4,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/ATen.h:5,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/types.h:3,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/data.h:3,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch/all.h:4,
                   from /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/torch/extension.h:4,
                   from csrc/cpu/convert_cpu.h:3,
                   from csrc/cpu/convert_cpu.cpp:1:   /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/aten_interned_strings.h:1001:9: note: ‘c10::attr::value’ declared here    1001 | _(attr, value) \
        |         ^~~~~   /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:373:35: note: in definition of macro ‘DEFINE_SYMBOL’
    373 |   namespace ns { constexpr Symbol s(static_cast<unique_t>(_keys::ns##_##s)); }
        |                                   ^   /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:204:3: note: in expansion of macro ‘FORALL_ATTR_BASE_SYMBOLS’
    204 |   FORALL_ATTR_BASE_SYMBOLS(_)        \
        |   ^~~~~~~~~~~~~~~~~~~~~~~~   /home/alva/python/foo-3.7/lib/python3.7/site-packages/torch/include/ATen/core/interned_strings.h:374:1: note: in expansion of macro ‘FORALL_NS_SYMBOLS’
    374 | FORALL_NS_SYMBOLS(DEFINE_SYMBOL)
        | ^~~~~~~~~~~~~~~~~   error: command 'x86_64-linux-gnu-gcc' failed with exit status 1   ----------------------------------------   ERROR: Failed building wheel for torch-sparse

I tried codes

sudo apt-get install python3.7-dev

sudo apt-get install libpq-dev python-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libffi-dev

sudo apt-get install python3.7-dev

sudo apt install build-essential

pip install torch-sparse -f https://data.pyg.org/whl/torch-1.4.0/torch_sparse-0.5.1+cpu-cp37-cp37m-linux_x86_64.whl

But I still get the same error. I have torch 1.4.0+cpu but I don't think torch version is the problem.

How can I get rid of this error? Thanks so much in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南街九尾狐 2025-01-18 04:42:47

您好,我终于解决了我的问题,所以我在这里发布我的解决方案。

首先,我需要澄清我需要安装 torch-sparse,并且我的命令中有拼写错误(我错误地复制粘贴了 torch-scatter 的代码)。但错误信息是正确的。

我所做的是卸载 ubuntu 20.04 并安装 ubuntu 18.04,其中默认 python 3.6.9。然后我继续使用默认的 python 版本创建一个 virtualenv,只需使用 pip install torch-sparse==0.5.1 即可运行。

Hello I finally solved my issue, so I post my solution here.

First I need to clarify that I need to install torch-sparse, and there's typo in my command(I copy paste the code for torch-scatter by mistake). But the error message is correct.

What I did is that I unintalled ubuntu 20.04 and installed ubuntu 18.04, which has default python 3.6.9. Then I proceed to create a virtualenv using default python version, and just use pip install torch-sparse==0.5.1 and it works now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文