mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.95k stars 563 forks source link

setup.py fails if `odbc_config` can't be found #1213

Open RA80533 opened 1 year ago

RA80533 commented 1 year ago

Issue

setup.py attempts to run odbc_config in the user's shell via os.popen():

https://github.com/mkleehammer/pyodbc/blob/7b4e27781c7f1b75995ecca73d3018c929f4adef/setup.py#L204

It then calls readlines() and assumes there will be at least 2 values to unpack and assign to cflags and ldflags:

https://github.com/mkleehammer/pyodbc/blob/7b4e27781c7f1b75995ecca73d3018c929f4adef/setup.py#L205

If odbc_config isn't found in the user's PATH, readlines() won't unpack anything and a ValueError will be raised. This issue is likely often to occur when a user is attempting to install pyodbc where it unfortunately produces an unhelpful error:

(example) RA80533@mbp example % python -m pip install --pre --no-binary :all: pyodbc
Collecting pyodbc
  Using cached pyodbc-4.0.39.tar.gz (282 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [20 lines of output]
      Traceback (most recent call last):
        File "/Users/RA80533/Desktop/example/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/Users/RA80533/Desktop/example/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/Users/RA80533/Desktop/example/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/rx/mgpqyfxd01q4w5yhxdctdfcm0000gn/T/pip-build-env-b_hshvm7/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/rx/mgpqyfxd01q4w5yhxdctdfcm0000gn/T/pip-build-env-b_hshvm7/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/rx/mgpqyfxd01q4w5yhxdctdfcm0000gn/T/pip-build-env-b_hshvm7/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 371, in <module>
        File "<string>", line 77, in main
        File "<string>", line 205, in get_compiler_settings
      ValueError: not enough values to unpack (expected 2, got 0)
      [end of output]

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

× Getting requirements to build wheel 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.
basnijholt commented 1 year ago

I just ran into this problem. Thanks for the fix in #1214.

@mkleehammer, could you perhaps review that PR? :)