安装 psycopg2 时,在 venv 上使用 pip 时,“错误:--plat-name 必须是 ('win32'、'win-amd64'、'win-arm32'、'win-arm64') 之一”

Aav*_*ane 6 python windows django postgresql psycopg2

点版本:23.1.1

\n

Python版本:3.9.11

\n

操作系统:Windows 11

\n

我的python项目已创建,并使用env作为虚拟环境。psycopg2 安装失败。\n根据日志,“psycopg2 的构建轮失败”,并且还显示“许可证文件参数已弃用”。

\n

尽管其他平台存在解决方案,但我还没有找到适合我的平台的任何解决方案。\nwheel 和 setuptools 都是最新的。

\n

pip install psycopg2-binary也不起作用。

\n

完整的错误如下:

\n
\n(env) PS C:\\\\Aavash files\\\\COMP206\\\\Project\\\\Movie4AllMoods\\> pip install psycopg2\nCollecting psycopg2\nUsing cached psycopg2-2.9.6.tar.gz (383 kB)\nPreparing metadata (setup.py) ... done\nBuilding wheels for collected packages: psycopg2\nBuilding wheel for psycopg2 (setup.py) ... error\nerror: subprocess-exited-with-error\n\n\xc3\x97 python setup.py bdist_wheel did not run successfully.\n\xe2\x94\x82 exit code: 1\n\xe2\x95\xb0\xe2\x94\x80\\> \\[34 lines of output\\]\nC:\\\\Aavash files\\\\COMP206\\\\Project\\\\Movie4AllMoods\\\\env\\\\lib\\\\python3.9\\\\site-packages\\\\setuptools\\\\config\\\\setupcfg.py:293: \\_DeprecatedConfig: Deprecated config in `setup.cfg`\n!!\n\n              ********************************************************************************\n              The license_file parameter is deprecated, use license_files instead.\n      \n              By 2023-Oct-30, you need to update your project and remove deprecated calls\n              or your builds will no longer be supported.\n      \n              See https://setuptools.pypa.io/en/latest/https://setuptools.pypa.io/en/latest/userguide/declarative_config.html for details.\n              ********************************************************************************\n      \n      !!\n        parsed = self.parsers.get(option_name, lambda x: x)(value)\n      running bdist_wheel\n      running build\n      running build_py\n      creating build\n      creating build\\lib.mingw_x86_64-cpython-39\n      creating build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      copying lib\\errorcodes.py -> build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      copying lib\\errors.py -> build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      copying lib\\extensions.py -> build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      copying lib\\extras.py -> build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      copying lib\\pool.py -> build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      copying lib\\sql.py -> build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      copying lib\\tz.py -> build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      copying lib\\_ipaddress.py -> build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      copying lib\\_json.py -> build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      copying lib\\_range.py -> build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      copying lib\\__init__.py -> build\\lib.mingw_x86_64-cpython-39\\psycopg2\n      running build_ext\n      building 'psycopg2._psycopg' extension\n      error: --plat-name must be one of ('win32', 'win-amd64', 'win-arm32', 'win-arm64')\n      [end of output]\n\nnote: This error originates from a subprocess, and is likely not a problem with pip.\nERROR: Failed building wheel for psycopg2\nRunning setup.py clean for psycopg2\nFailed to build psycopg2\nERROR: Could not build wheels for psycopg2, which is required to install pyproject.toml-based projects\n
Run Code Online (Sandbox Code Playgroud)\n
\n

我尝试过更新 pip、wheel 和设置工具,但没有成功。我发现的其他所有内容都是我无法运行的 Linux 命令。它在全局中安装良好,但在我的虚拟环境中显示错误。我已经尝试了一切,但似乎没有任何效果。

\n

小智 6

msys2 用户还可以从以下线程的评论之一中受益。

https://github.com/pyproj4/pyproj/issues/1009

SETUPTOOLS_USE_DISTUTILS=stdlib pip install <your package name>
Run Code Online (Sandbox Code Playgroud)

正如 github 票证中所说

据我收集的信息:由于 setuptools>=60.0.0 setuptools“包括 distutils 的本地供应副本”。因此,除非您制作,否则不会使用标准库 distutils 的 MSYS2 修补版本


小智 1

就我而言,我必须走这条路 C:\msys64\mingw64\lib\python3.9\site-packages\setuptools\_distutils

发生错误的地方。在你的情况下,它必须是路径 C:\Aavash files\COMP206\Project\Movie4AllMoods\env\lib\python3.9\site-packages\setuptools\config\setupcfg.py

当您打开文件时,搜索该文件中的变量plat_name

你会发现这样的代码块:

`def __init__(self, verbose=0, dry_run=0, force=0):
    super().__init__(verbose, dry_run, force)
    # target platform (.plat_name is consistent with 'bdist')
    self.plat_name = None
    self.initialized = False`
Run Code Online (Sandbox Code Playgroud)

None将中的更改self.plat_name为您平台的版本,如果是 64 位系统则为'win-arm64',如果您的设备中有 AMD 处理器则为'win-amd64'

您可以检查PLAT_TO_VCVARS该文件中的变量,它将列出所有可用的平台。

`PLAT_TO_VCVARS = {
'win32' : 'x86',
'win-amd64' : 'x86_amd64',
'win-arm32' : 'x86_arm',
'win-arm64' : 'x86_arm64'
Run Code Online (Sandbox Code Playgroud)

}`

再次搜索plat_name,会发现这样的代码块:

`def initialize(self, plat_name=None):
    # multi-init means we would need to check platform same each time...
    assert not self.initialized, "don't init multiple times"
    if plat_name is None:
        plat_name = get_platform()
    # sanity check for platforms to prevent obscure errors later.
    if plat_name not in PLAT_TO_VCVARS:
        raise DistutilsPlatformError("--plat-name must be one of {}"
                                     .format(tuple(PLAT_TO_VCVARS)))

    # Get the vcvarsall.bat spec for the requested platform.
    plat_spec = PLAT_TO_VCVARS[plat_name]`
Run Code Online (Sandbox Code Playgroud)

None将in更改plat_name = None为您的平台名称,在我的例子中,它是'win-amd64'.

这样做,希望您的错误能够得到解决。