"error: --plat-name must be one of ('win32', 'win-amd64', 'win-arm32', 'win-arm64')" with pip on venv while installing psycopg2
Asked Answered
E

3

8

pip version: 23.1.1

Python version: 3.9.11

OS: Windows 11

My python project is created and env is used as virtual environment. psycopg2 fails to install. According to log, "Failed building wheel for psycopg2" and it also shows that the "The license_file parameter is deprecated".

I have not found any solutions for my platform even though the solution exists for other platforms. Both wheel and setuptools are latest.

pip install psycopg2-binary also does not work.

The full error is below:


(env) PS C:\\Aavash files\\COMP206\\Project\\Movie4AllMoods\> pip install psycopg2
Collecting psycopg2
Using cached psycopg2-2.9.6.tar.gz (383 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: psycopg2
Building wheel for psycopg2 (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─\> \[34 lines of output\]
C:\\Aavash files\\COMP206\\Project\\Movie4AllMoods\\env\\lib\\python3.9\\site-packages\\setuptools\\config\\setupcfg.py:293: \_DeprecatedConfig: Deprecated config in `setup.cfg`
!!

              ********************************************************************************
              The license_file parameter is deprecated, use license_files instead.
      
              By 2023-Oct-30, you need to update your project and remove deprecated calls
              or your builds will no longer be supported.
      
              See https://setuptools.pypa.io/en/latest/https://setuptools.pypa.io/en/latest/userguide/declarative_config.html for details.
              ********************************************************************************
      
      !!
        parsed = self.parsers.get(option_name, lambda x: x)(value)
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.mingw_x86_64-cpython-39
      creating build\lib.mingw_x86_64-cpython-39\psycopg2
      copying lib\errorcodes.py -> build\lib.mingw_x86_64-cpython-39\psycopg2
      copying lib\errors.py -> build\lib.mingw_x86_64-cpython-39\psycopg2
      copying lib\extensions.py -> build\lib.mingw_x86_64-cpython-39\psycopg2
      copying lib\extras.py -> build\lib.mingw_x86_64-cpython-39\psycopg2
      copying lib\pool.py -> build\lib.mingw_x86_64-cpython-39\psycopg2
      copying lib\sql.py -> build\lib.mingw_x86_64-cpython-39\psycopg2
      copying lib\tz.py -> build\lib.mingw_x86_64-cpython-39\psycopg2
      copying lib\_ipaddress.py -> build\lib.mingw_x86_64-cpython-39\psycopg2
      copying lib\_json.py -> build\lib.mingw_x86_64-cpython-39\psycopg2
      copying lib\_range.py -> build\lib.mingw_x86_64-cpython-39\psycopg2
      copying lib\__init__.py -> build\lib.mingw_x86_64-cpython-39\psycopg2
      running build_ext
      building 'psycopg2._psycopg' extension
      error: --plat-name must be one of ('win32', 'win-amd64', 'win-arm32', 'win-arm64')
      [end of output]

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

I have tried updating pip, wheel and setup tools but that didn't work. Everything else I found were linux commands that I have been unable to run. It installed fine in global but shows errors in my virtual environment. I have tried everything but nothing seems to work.

Eiderdown answered 22/4, 2023 at 12:18 Comment(4)
What were the linux commands suggesting?Korella
I have never had this problem with psycopg2-binary. Is the error message the same there? It might be a version thing. I'll try test shortlyKorella
linux commands suggested t install the libpq-dev library which is not a requirement in windows. And yes the error message is exactly same in psycopg2-binary.Eiderdown
the error only exists in a virtual environment. It installed successfully in global.Eiderdown
T
9

msys2 users may also benefit from one of the comments on the following thread.

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

SETUPTOOLS_USE_DISTUTILS=stdlib pip install <your package name>

As said in the github ticket

From what I gather: Since setuptools>=60.0.0 setuptools "includes a local, vendored copy of distutils". Therefore the MSYS2 patched version of standard libary distutils is not used unless you make it

Tableware answered 11/8, 2023 at 10:45 Comment(0)
S
1

In my case I had to go to the path C:\msys64\mingw64\lib\python3.9\site-packages\setuptools\_distutils

where the error occurred. In your case, it must be the path C:\Aavash files\COMP206\Project\Movie4AllMoods\env\lib\python3.9\site-packages\setuptools\config\setupcfg.py

When you open the file search for the variable plat_name in that file.

You will find a code block like this:

`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`

Change the None in self.plat_name to your platform's version, if it is a 64bit system then it will be 'win-arm64', if you have the AMD processor in your device, then it will be 'win-amd64'.

You can check the PLAT_TO_VCVARS variable in that file, it will list all the available platforms.

`PLAT_TO_VCVARS = {
'win32' : 'x86',
'win-amd64' : 'x86_amd64',
'win-arm32' : 'x86_arm',
'win-arm64' : 'x86_arm64'

}`

Search for plat_name again, and you will find a code block like this:

`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]`

Change the None in plat_name = None to your platform name, in my case, it was 'win-amd64'.

Do this and hopefully, your error will be resolved.

Sandrasandro answered 10/5, 2023 at 18:14 Comment(0)
P
1

I was using Python 3.10 on a Windows 11 OS and was running into the same issue. The simplest solution would be to update your current version of Python.

After uninstalling Python 3.10.5 from my computer and installing Python 3.11.7 I was able to install psycopg2 without any issues using the command

pip install psycopg2

@Drishya has the work-around solution here as well if you need to keep your current version of Python.

Pape answered 9/12, 2023 at 15:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.