无法 pip install pandas... 来自子进程的错误

Can't pip install pandas... error from a subprocess

我正在尝试安装 pandas 以在我的 python 代码中使用。我可以使用 pip install upgrade pip 升级我的 pip,但是当我尝试使用 pip install pandas 安装 pandas 时,出现以下错误:

Traceback (most recent call last):
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\fcompiler\compaq.py", line 78
      , in CompaqVisualFCompiler
        m.initialize()
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\msvccompiler.py", line 48, in
     initialize
        _MSVCCompiler.initialize(self)
      File "C:\msys64\mingw64\lib\python3.9\distutils\msvccompiler.py", line 259, in initialize
        self.__paths = self.get_msvc_paths("path")
      File "C:\msys64\mingw64\lib\python3.9\distutils\msvccompiler.py", line 602, in get_msvc_paths
        r"\Win32 (%s)\Directories" % (self.__root, platform))
    AttributeError: 'MSVCCompiler' object has no attribute '_MSVCCompiler__root'
 
    During handling of the above exception, another exception occurred:
 
    Traceback (most recent call last):
      File "C:\Users\Brian\AppData\Local\Temp\tmp94oxoujq_in_process.py", line 363, in <module>
        main()
      File "C:\Users\Brian\AppData\Local\Temp\tmp94oxoujq_in_process.py", line 345, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "C:\Users\Brian\AppData\Local\Temp\tmp94oxoujq_in_process.py", line 164, in prepare_metadata_for_build_wheel
        return hook(metadata_directory, config_settings)
      File "C:\Users\Brian\AppData\Local\Temp\pip-build-env-tr54un10\overlay\lib\python3.9\site-packages\setuptools\build_meta.py", line 157, in prepare
    e_metadata_for_build_wheel
        self.run_setup()
      File "C:\Users\Brian\AppData\Local\Temp\pip-build-env-tr54un10\overlay\lib\python3.9\site-packages\setuptools\build_meta.py", line 248, in run_se
    tup
        super(_BuildMetaLegacyBackend,
      File "C:\Users\Brian\AppData\Local\Temp\pip-build-env-tr54un10\overlay\lib\python3.9\site-packages\setuptools\build_meta.py", line 142, in run_se
    tup
        exec(compile(code, __file__, 'exec'), locals())
      File "setup.py", line 508, in <module>
        setup_package()
      File "setup.py", line 500, in setup_package
        setup(**metadata)
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\core.py", line 169, in setup 
        return old_setup(**new_attr)
      File "C:\Users\Brian\AppData\Local\Temp\pip-build-env-tr54un10\overlay\lib\python3.9\site-packages\setuptools\__init__.py", line 165, in setup   
        return distutils.core.setup(**attrs)
      File "C:\msys64\mingw64\lib\python3.9\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "C:\msys64\mingw64\lib\python3.9\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "C:\msys64\mingw64\lib\python3.9\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\Brian\AppData\Local\Temp\pip-build-env-tr54un10\overlay\lib\python3.9\site-packages\setuptools\command\dist_info.py", line 31, in 
    run
        egg_info.run()
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\command\egg_info.py", line 24
    , in run
        self.run_command("build_src")
      File "C:\msys64\mingw64\lib\python3.9\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\msys64\mingw64\lib\python3.9\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\command\build_src.py", line 1
    44, in run
        self.build_sources()
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\command\build_src.py", line 1
    55, in build_sources
        self.build_library_sources(*libname_info)
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\command\build_src.py", line 2
    88, in build_library_sources
        sources = self.generate_sources(sources, (lib_name, build_info))
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\command\build_src.py", line 3
    78, in generate_sources
        source = func(extension, build_dir)
      File "numpy\core\setup.py", line 658, in get_mathlib_info
        st = config_cmd.try_link('int main(void) { return 0;}')
      File "C:\msys64\mingw64\lib\python3.9\distutils\command\config.py", line 241, in 
    try_link
        self._check_compiler()
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\command\config.py", line 80, 
    in _check_compiler
        self.fcompiler = new_fcompiler(compiler=self.fcompiler,
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\fcompiler\__init__.py", line 
    876, in new_fcompiler
        load_all_fcompiler_classes()
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\fcompiler\__init__.py", line 
    777, in load_all_fcompiler_classes
        __import__ (module_name)
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\fcompiler\compaq.py", line 54
    , in <module>
        class CompaqVisualFCompiler(FCompiler):
      File "C:\Users\Brian\AppData\Local\Temp\pip-install-i72pcle8\numpy_328f6081d36f426b90572be17f203722\numpy\distutils\fcompiler\compaq.py", line 83
    , in CompaqVisualFCompiler
        if '_MSVCCompiler__root' in str(msg):
    NameError: name 'msg' is not defined
    [end of output]
 
    note: This error originates from a subprocess, and is likely not a problem with pip.
  error: metadata-generation-failed
 
  Encountered error while generating package metadata.
 
  See above for output.
 
  note: This is an issue with the package mentioned above, not pip.
  hint: See above for details.
  [end of output]
    × pip subprocess to install build dependencies did not run successfully.
    │ exit code: 1
    ╰─> See above for output.

    note: This error originates from a subprocess, and is likely not a problem with pip.

在升级我的 pip 之前,我尝试安装 pandas,但是我尝试安装的 none 版本会下载;但是,我不认为我在升级 pip 之前遇到了这些相同的错误。谁能帮我弄清楚如何安装 pandas?在不使用 pip install pandas 的情况下,是否有其他不同的安装方式?

删除 NumPy,然后尝试重新安装 pandas。

pip uninstall package_name