Bug #87475 UnboundLocalError: local variable 'include_dirs' referenced before assignment
Submitted: 18 Aug 2017 13:47 Modified: 29 Aug 2017 12:35
Reporter: Shahriyar Rzayev (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version:8.0.4 OS:CentOS (7)
Assigned to: CPU Architecture:Any

[18 Aug 2017 13:47] Shahriyar Rzayev
Description:
I have cloned repo and did following things:

export MYSQLXPB_PROTOBUF_INCLUDE_DIR=/usr/include/google/protobuf
export MYSQLXPB_PROTOBUF_LIB_DIR=/usr/lib/x86_64-linux-gnu
export MYSQLXPB_PROTOC=/usr/bin/protoc

$ python setup.py install --with-mysql-capi=/home/shahriyar.rzaev/MYROCKS/PS-5.7-trunk_dbg/include/my_config.h 
running install
Installing MySQL C Extension
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/mysql
copying lib/mysql/__init__.py -> build/lib.linux-x86_64-2.7/mysql
creating build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/errors.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/__init__.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/custom_types.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/cursor_cext.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/catch23.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/conversion.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/protocol.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/dbapi.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/cursor.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/constants.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/abstracts.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/utils.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/version.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/charsets.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/optionfiles.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/errorcode.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/connection.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/connection_cext.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/network.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/authentication.py -> build/lib.linux-x86_64-2.7/mysql/connector
copying lib/mysql/connector/pooling.py -> build/lib.linux-x86_64-2.7/mysql/connector
creating build/lib.linux-x86_64-2.7/mysql/connector/locales
copying lib/mysql/connector/locales/__init__.py -> build/lib.linux-x86_64-2.7/mysql/connector/locales
creating build/lib.linux-x86_64-2.7/mysql/connector/locales/eng
copying lib/mysql/connector/locales/eng/__init__.py -> build/lib.linux-x86_64-2.7/mysql/connector/locales/eng
copying lib/mysql/connector/locales/eng/client_error.py -> build/lib.linux-x86_64-2.7/mysql/connector/locales/eng
creating build/lib.linux-x86_64-2.7/mysql/connector/django
copying lib/mysql/connector/django/validation.py -> build/lib.linux-x86_64-2.7/mysql/connector/django
copying lib/mysql/connector/django/schema.py -> build/lib.linux-x86_64-2.7/mysql/connector/django
copying lib/mysql/connector/django/__init__.py -> build/lib.linux-x86_64-2.7/mysql/connector/django
copying lib/mysql/connector/django/base.py -> build/lib.linux-x86_64-2.7/mysql/connector/django
copying lib/mysql/connector/django/creation.py -> build/lib.linux-x86_64-2.7/mysql/connector/django
copying lib/mysql/connector/django/client.py -> build/lib.linux-x86_64-2.7/mysql/connector/django
copying lib/mysql/connector/django/features.py -> build/lib.linux-x86_64-2.7/mysql/connector/django
copying lib/mysql/connector/django/introspection.py -> build/lib.linux-x86_64-2.7/mysql/connector/django
copying lib/mysql/connector/django/compiler.py -> build/lib.linux-x86_64-2.7/mysql/connector/django
copying lib/mysql/connector/django/operations.py -> build/lib.linux-x86_64-2.7/mysql/connector/django
creating build/lib.linux-x86_64-2.7/mysql/connector/fabric
copying lib/mysql/connector/fabric/__init__.py -> build/lib.linux-x86_64-2.7/mysql/connector/fabric
copying lib/mysql/connector/fabric/balancing.py -> build/lib.linux-x86_64-2.7/mysql/connector/fabric
copying lib/mysql/connector/fabric/caching.py -> build/lib.linux-x86_64-2.7/mysql/connector/fabric
copying lib/mysql/connector/fabric/connection.py -> build/lib.linux-x86_64-2.7/mysql/connector/fabric
creating build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/result.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/errors.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/expr.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/__init__.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/compat.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/crud.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/protocol.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/protobuf.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/statement.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/dbdoc.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/constants.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/charsets.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/errorcode.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/connection.py -> build/lib.linux-x86_64-2.7/mysqlx
copying lib/mysqlx/authentication.py -> build/lib.linux-x86_64-2.7/mysqlx
creating build/lib.linux-x86_64-2.7/mysqlx/locales
copying lib/mysqlx/locales/__init__.py -> build/lib.linux-x86_64-2.7/mysqlx/locales
creating build/lib.linux-x86_64-2.7/mysqlx/locales/eng
copying lib/mysqlx/locales/eng/__init__.py -> build/lib.linux-x86_64-2.7/mysqlx/locales/eng
copying lib/mysqlx/locales/eng/client_error.py -> build/lib.linux-x86_64-2.7/mysqlx/locales/eng
running build_ext
# Python architecture: 64-bit
# Python ARCH_64BIT: True
Traceback (most recent call last):
  File "setup.py", line 64, in <module>
    ext_modules=setupinfo.extensions,
  File "/usr/lib64/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib64/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/shahriyar.rzaev/mysql-connector-python/lib/cpy_distutils.py", line 822, in run
    install.run(self)
  File "/usr/lib64/python2.7/distutils/command/install.py", line 563, in run
    self.run_command('build')
  File "/usr/lib64/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib64/python2.7/distutils/command/build.py", line 127, in run
    self.run_command(cmd_name)
  File "/usr/lib64/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/lib64/python2.7/distutils/dist.py", line 971, in run_command
    cmd_obj.ensure_finalized()
  File "/usr/lib64/python2.7/distutils/cmd.py", line 109, in ensure_finalized
    self.finalize_options()
  File "/home/shahriyar.rzaev/mysql-connector-python/lib/cpy_distutils.py", line 435, in finalize_options
    self._finalize_connector_c(self.with_mysql_capi)
  File "/home/shahriyar.rzaev/mysql-connector-python/lib/cpy_distutils.py", line 397, in _finalize_connector_c
    for include_dir in include_dirs:
UnboundLocalError: local variable 'include_dirs' referenced before assignment

How to repeat:
See description
[21 Aug 2017 11:55] Shahriyar Rzayev
Added version and tested OS
[28 Aug 2017 17:15] Jose Israel Gomez Delgado
Hi Shahriyar Rzayev, thanks for for your bug report.

The use of the --with-mysql-capi option should specify the location of the c-extension or the location of the mysql_config executable (located on the server's bin folder).

In addition to install Connector python from source we need to specify the location of protobuf using the following options, support for environment variables is not supported yet.|

--with-protobuf-include-dir=<protobuf include folder>
--with-protobuf-lib-dir=<protobuf lib folder>
--with-protoc=<protobuf protoc executable binary>

as in example:
--with-protobuf-include-dir=protobuf-2.6.x-y/include/
--with-protobuf-lib-dir=protobuf-2.6..x-y/lib
--with-protoc=protobuf-2.6..x-y/bin/protoc

However, We will update our install from source documentation very shortly, Thanks for use C/py.
[29 Aug 2017 10:25] Shahriyar Rzayev
Hi Jose Israel Gomez Delgado,

Thanks for reply.

Tried as you said:

$ python setup.py install --with-protobuf-include-dir=/usr/include/google/protobuf --with-protobuf-lib-dir=/usr/lib/x86_64-linux-gnu --with-protoc=/usr/bin/protoc --with-mysql-capi=/home/shahriyar.rzaev/MYROCKS/PS250817-percona-server-5.7.19-17-linux-x86_64-debug/bin
running install
Installing MySQL C Extension
running build
running build_py
running build_ext
# Python architecture: 64-bit
# Python ARCH_64BIT: True
MySQL C API installation invalid (my_config.h not found)

So I should provide not the path of mysql_config, but the full file name.
[29 Aug 2017 10:38] Shahriyar Rzayev
Also see:

https://bugs.mysql.com/bug.php?id=87578
[29 Aug 2017 12:35] Chiranjeevi Battula
Hello Shahriyar,

Thank you for feedback.
As Jose confirmed in the earlier note, this will be updated shortly in our install from source documentation.
I'm closing the bug for now.

Thanks,
Chiranjeevi.