win11 wsl ubuntu20.4 conda 安装 pycocotools 时出现bug

在尝试通过pip安装pycocotools时遇到编译错误,提示gcc找不到。为了解决这个问题,建议使用conda环境来安装pycocotools。通过运行condainstall-cconda-forgepycocotools命令,成功下载并更新了相关依赖包,解决了安装问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

时间:2023.7.9

BUG:

Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting pycocotools
  Downloading https://mirrors.aliyun.com/pypi/packages/ef/c6/90220be3b39fbc4cbd203775ca47dd8dc97fae06fbd2b500637395621b7c/pycocotools-2.0.6.tar.gz (24 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: matplotlib>=2.1.0 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from pycocotools) (3.7.2)
Requirement already satisfied: numpy in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from pycocotools) (1.24.4)
Requirement already satisfied: contourpy>=1.0.1 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from matplotlib>=2.1.0->pycocotools) (1.1.0)
Requirement already satisfied: cycler>=0.10 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from matplotlib>=2.1.0->pycocotools) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from matplotlib>=2.1.0->pycocotools) (4.40.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from matplotlib>=2.1.0->pycocotools) (1.4.4)
Requirement already satisfied: packaging>=20.0 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from matplotlib>=2.1.0->pycocotools) (23.1)
Requirement already satisfied: pillow>=6.2.0 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from matplotlib>=2.1.0->pycocotools) (9.3.0)
Requirement already satisfied: pyparsing<3.1,>=2.3.1 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from matplotlib>=2.1.0->pycocotools) (3.0.9)
Requirement already satisfied: python-dateutil>=2.7 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from matplotlib>=2.1.0->pycocotools) (2.8.2)
Requirement already satisfied: importlib-resources>=3.2.0 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from matplotlib>=2.1.0->pycocotools) (6.0.0)
Requirement already satisfied: zipp>=3.1.0 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from importlib-resources>=3.2.0->matplotlib>=2.1.0->pycocotools) (3.16.0)
Requirement already satisfied: six>=1.5 in /root/anaconda3/envs/mmdetection3/lib/python3.8/site-packages (from python-dateutil>=2.7->matplotlib>=2.1.0->pycocotools) (1.16.0)
Building wheels for collected packages: pycocotools
  Building wheel for pycocotools (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for pycocotools (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [20 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-38
      creating build/lib.linux-x86_64-cpython-38/pycocotools
      copying pycocotools/mask.py -> build/lib.linux-x86_64-cpython-38/pycocotools
      copying pycocotools/coco.py -> build/lib.linux-x86_64-cpython-38/pycocotools
      copying pycocotools/cocoeval.py -> build/lib.linux-x86_64-cpython-38/pycocotools
      copying pycocotools/__init__.py -> build/lib.linux-x86_64-cpython-38/pycocotools
      running build_ext
      cythoning pycocotools/_mask.pyx to pycocotools/_mask.c
      building 'pycocotools._mask' extension
      creating build/temp.linux-x86_64-cpython-38
      creating build/temp.linux-x86_64-cpython-38/common
      creating build/temp.linux-x86_64-cpython-38/pycocotools
      gcc -pthread -B /root/anaconda3/envs/mmdetection3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/tmp/pip-build-env-81ye_g9x/overlay/lib/python3.8/site-packages/numpy/core/include -I./common -I/root/anaconda3/envs/mmdetection3/include/python3.8 -c ./common/maskApi.c -o build/temp.linux-x86_64-cpython-38/./common/maskApi.o -Wno-cpp -Wno-unused-function -std=c99
      /tmp/pip-build-env-81ye_g9x/overlay/lib/python3.8/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-install-s00_pyri/pycocotools_c850da5be55142cf9ce244e31f5d2178/pycocotools/_mask.pyx
        tree = Parsing.p_module(s, pxd, full_module_name)
      error: command 'gcc' failed: No such file or directory
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pycocotools
Failed to build pycocotools
ERROR: Could not build wheels for pycocotools, which is required to install pyproject.toml-based projects

解决方法:
用conda安装

 conda install -c conda-forge pycocotools

就好啦

Collecting package metadata (current_repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 23.3.1
  latest version: 23.5.0

Please update conda by running

    $ conda update -n base -c defaults conda

Or to minimize the number of packages updated during conda update use

     conda install conda=23.5.0



## Package Plan ##

  environment location: /root/anaconda3/envs/mmdetection3

  added / updated specs:
    - pycocotools


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _libgcc_mutex-0.1          |      conda_forge           3 KB  conda-forge
    _openmp_mutex-4.5          |       2_kmp_llvm           6 KB  conda-forge
    ca-certificates-2023.5.7   |       hbcca054_0         145 KB  conda-forge
    certifi-2023.5.7           |     pyhd8ed1ab_0         149 KB  conda-forge
    cycler-0.11.0              |     pyhd8ed1ab_0          10 KB  conda-forge
    kiwisolver-1.4.4           |   py38h6a678d5_0          76 KB
    libgcc-ng-13.1.0           |       he5830b7_0         758 KB  conda-forge
    llvm-openmp-14.0.6         |       h9e868ea_0         4.4 MB
    matplotlib-base-3.4.3      |   py38hf4fb855_1         7.3 MB  conda-forge
    mkl-service-2.4.0          |   py38h5eee18b_1          54 KB
    mkl_fft-1.3.6              |   py38h417a72b_1         215 KB
    mkl_random-1.2.2           |   py38h417a72b_1         309 KB
    numpy-1.24.3               |   py38hf6e8229_1          10 KB
    numpy-base-1.24.3          |   py38h060ed82_1         6.2 MB
    openssl-3.1.1              |       hd590300_1         2.5 MB  conda-forge
    pycocotools-2.0.6          |   py38h26c90d9_1         111 KB  conda-forge
    pyparsing-3.1.0            |     pyhd8ed1ab_0          87 KB  conda-forge
    python-dateutil-2.8.2      |     pyhd8ed1ab_0         240 KB  conda-forge
    python_abi-3.8             |           2_cp38           4 KB  conda-forge
    six-1.16.0                 |     pyh6c4a22f_0          14 KB  conda-forge
    tornado-6.3.2              |   py38h01eb140_0         613 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        23.2 MB

The following NEW packages will be INSTALLED:

  certifi            conda-forge/noarch::certifi-2023.5.7-pyhd8ed1ab_0
  cycler             conda-forge/noarch::cycler-0.11.0-pyhd8ed1ab_0
  kiwisolver         pkgs/main/linux-64::kiwisolver-1.4.4-py38h6a678d5_0
  llvm-openmp        pkgs/main/linux-64::llvm-openmp-14.0.6-h9e868ea_0
  matplotlib-base    conda-forge/linux-64::matplotlib-base-3.4.3-py38hf4fb855_1
  mkl-service        pkgs/main/linux-64::mkl-service-2.4.0-py38h5eee18b_1
  mkl_fft            pkgs/main/linux-64::mkl_fft-1.3.6-py38h417a72b_1
  mkl_random         pkgs/main/linux-64::mkl_random-1.2.2-py38h417a72b_1
  numpy              pkgs/main/linux-64::numpy-1.24.3-py38hf6e8229_1
  numpy-base         pkgs/main/linux-64::numpy-base-1.24.3-py38h060ed82_1
  pycocotools        conda-forge/linux-64::pycocotools-2.0.6-py38h26c90d9_1
  pyparsing          conda-forge/noarch::pyparsing-3.1.0-pyhd8ed1ab_0
  python-dateutil    conda-forge/noarch::python-dateutil-2.8.2-pyhd8ed1ab_0
  python_abi         conda-forge/linux-64::python_abi-3.8-2_cp38
  six                conda-forge/noarch::six-1.16.0-pyh6c4a22f_0
  tornado            conda-forge/linux-64::tornado-6.3.2-py38h01eb140_0

The following packages will be REMOVED:

  libgomp-11.2.0-h1234567_1

The following packages will be UPDATED:

  libgcc-ng          pkgs/main::libgcc-ng-11.2.0-h1234567_1 --> conda-forge::libgcc-ng-13.1.0-he5830b7_0
  openssl               pkgs/main::openssl-3.0.9-h7f8727e_0 --> conda-forge::openssl-3.1.1-hd590300_1

The following packages will be SUPERSEDED by a higher-priority channel:

  _libgcc_mutex           pkgs/main::_libgcc_mutex-0.1-main --> conda-forge::_libgcc_mutex-0.1-conda_forge
  _openmp_mutex          pkgs/main::_openmp_mutex-5.1-1_gnu --> conda-forge::_openmp_mutex-4.5-2_kmp_llvm
  ca-certificates    pkgs/main::ca-certificates-2023.05.30~ --> conda-forge::ca-certificates-2023.5.7-hbcca054_0


Proceed ([y]/n)? y


Downloading and Extracting Packages

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
<think>好的,我需要帮助用户在Windows 11上通过WSL安装Ubuntu 20.04,以实现类似双系统的环境。首先,我得回顾一下用户提供的引用内容,看看有哪些步骤已经覆盖,哪些可能需要进一步说明。 根据引用[1],安装WSL2需要启用Hyper-V和“适用于Linux的Windows子系统”。然后更新Linux内核,设置WSL2为默认版本,接着安装Ubuntu 20.04并移动到自定义路径。用户可能希望自定义安装位置,所以需要详细说明如何移动虚拟环境,尤其是新版本WSL的操作可能不同,需要注意区分。 引用[2]提到通过微软商店安装Ubuntu 20.04,设置账户和密码,以及后续安装桌面环境的部分。不过用户主要需求是实现双系统环境,可能不需要桌面环境,但可以作为一个可选步骤提及。另外,更换软件源可能对后续使用有帮助,需要简要提到。 引用[3]解释了WSL的基本概念和好处,强调其便利性。在回答中需要确保用户理解WSL和传统双系统的区别,因为WSL并非真正的双系统,而是子系统,这对用户预期管理很重要。 接下来,我需要按照用户提供的系统级指令组织回答。必须使用中文,结构清晰,分步骤说明,并确保所有数学公式正确使用$...$或$$...$$格式,不过当前问题不涉及数学内容,可能不需要。但要注意LaTeX语法正确,例如在代码块或路径中使用反斜杠等。 用户的问题是关于安装步骤,所以需要分步骤指导,可能包括启用功能、安装WSL2、安装Ubuntu、移动安装位置、初始化账户等。同,生成的相关问题需要与WSLUbuntu安装、配置优化等相关。 需要确认步骤是否正确,例如在Windows 11中,某些步骤可能已经简化,比如启用WSL可能只需要一条命令。同,移动虚拟环境的步骤需要检查是否适用于最新版WSL,因为引用[1]提到新版本的方法可能不同,可能需要使用wsl --export和--import命令。 另外,用户提到“实现双系统环境”,可能需要澄清WSL和传统双启动的区别,避免误解。WSL是在Windows内部运行,而不是独立分区启动,所以需要明确说明这一点,确保用户理解。 最后,生成相关问题要围绕安装步骤、优化、使用技巧等,例如询问如何配置WSLWindows的文件交互,如何备份子系统,如何升级WSL版本等。 总结回答结构: 1. 澄清WSL与传统双系统的区别 2. 分步骤安装指南: a. 启用必要功能 b. 安装WSL2并更新内核 c. 安装Ubuntu 20.04 d. 移动虚拟环境(可选) e. 初始化账户 3. 可选步骤:安装桌面环境 4. 注意事项和常见问题 5. 相关问题 需要确保每个步骤清晰,代码块正确,路径示例明确,同引用正确的引用标记。例如,启用功能的部分引用[1],安装步骤引用[2],概念部分引用[3]。 检查是否有遗漏步骤,如设置默认版本为WSL2,安装后的初始化,以及如何访问Linux文件系统。同,提醒用户安装完成后可能需要执行系统更新,如sudo apt update && sudo apt upgrade。 可能还需要提及如何启动和关闭子系统,以及基本命令,但用户问题主要是安装过程,所以可能不需要深入,但可以简要提及。 现在,组织这些内容,确保符合用户的要求,结构清晰,步骤正确,并自然融入引用标记。</think>在Windows 11上通过WSL安装Ubuntu 20.04,可实现类似双系统的开发环境。以下是详细步骤: --- ### **步骤1:启用WSL相关功能** 1. **以管理员身份打开PowerShell**,运行以下命令启用Hyper-V和WSL: ```powershell dism.exe /online /enable-feature /featurename:Microsoft-Hyper-V /all /norestart dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart ``` 重启电脑以生效[^1]。 2. **设置WSL 2为默认版本**: ```powershell wsl --set-default-version 2 ``` --- ### **步骤2:安装Ubuntu 20.04** 1. **通过微软商店安装**: - 打开 **Microsoft Store**,搜索 **Ubuntu 20.04 LTS** 并安装[^2]。 - 安装完成后,在开始菜单中点击Ubuntu图标启动。 2. **初始化Ubuntu系统**: - 首次启动需等待解压完成,随后设置**用户名和密码**(密码输入不可见,按回车确认)。 --- ### **步骤3:迁移虚拟环境(可选)** 若需自定义安装路径(如D盘),按以下操作: 1. **导出Ubuntu镜像**: ```powershell wsl --export Ubuntu-20.04 d:\ubuntu20.04.tar ``` 2. **注销原有子系统并重新导入**: ```powershell wsl --unregister Ubuntu-20.04 wsl --import Ubuntu-20.04 d:\wsl\ubuntu d:\ubuntu20.04.tar --version 2 ``` 3. 设置默认用户: ```powershell ubuntu2004 config --default-user <用户名> ``` 此步骤适用于新版WSL,路径需根据实际情况调整[^1]。 --- ### **步骤4:基础配置** 1. **更新软件源**: ```bash sudo apt update && sudo apt upgrade -y ``` 2. **访问文件系统**: - 在Windows资源管理器中输入 `\\wsl$`,可直接访问Ubuntu文件。 --- ### **注意事项** - WSL 2基于轻量级虚拟机,性能接近原生Linux,但**非传统双系统**(无需分区或重启切换)[^3]。 - 若需图形界面,可安装桌面环境(如Xfce)并通过第三方X服务器(如VcXsrv)显示[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值