Bug #79766 pip install error: "option --single-version-externally-managed not recognized"
Submitted: 23 Dec 2015 17:30 Modified: 6 May 2022 22:19
Reporter: M B Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version:master OS:Any
Assigned to: CPU Architecture:Any

[23 Dec 2015 17:30] M B
Description:
`pip` has become the preferred method to install and manage Python components.

`pip install` fails on "error: option --single-version-externally-managed not recognized".

How to repeat:
The following occurs when installing using certain versions of `pip`/`setuptools` (attempted on Debian Jessie):

```sh
vagrant@bad:~$ git clone https://github.com/mysql/mysql-connector-python.git mysql-mysql-connector-python
Cloning into 'mysql-mysql-connector-python'...
remote: Counting objects: 1560, done.
remote: Total 1560 (delta 0), reused 0 (delta 0), pack-reused 1559
Receiving objects: 100% (1560/1560), 675.71 KiB | 685.00 KiB/s, done.
Resolving deltas: 100% (913/913), done.
Checking connectivity... done.
vagrant@bad:~$ python -m virtualenv ./test-mysql-connector
Running virtualenv with interpreter /usr/bin/python2
New python executable in ./test-mysql-connector/bin/python2
Also creating executable in ./test-mysql-connector/bin/python
Installing setuptools, pip...done.
vagrant@bad:~$ ./test-mysql-connector/bin/pip install ./mysql-mysql-connector-python
Unpacking ./mysql-mysql-connector-python
  Running setup.py (path:/tmp/pip-Ln020b-build/setup.py) egg_info for package from file:///home/vagrant/mysql-mysql-connector-python

Installing collected packages: mysql-connector-python
  Running setup.py install for mysql-connector-python
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: option --single-version-externally-managed not recognized
    Complete output from command /home/vagrant/test-mysql-connector/bin/python2 -c "import setuptools, tokenize;__file__='/tmp/pip-Ln020b-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-eXmiqs-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/vagrant/test-mysql-connector/include/site/python2.7:
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]

   or: -c --help [cmd1 cmd2 ...]

   or: -c --help-commands

   or: -c cmd --help

error: option --single-version-externally-managed not recognized

----------------------------------------
Cleaning up...
Command /home/vagrant/test-mysql-connector/bin/python2 -c "import setuptools, tokenize;__file__='/tmp/pip-Ln020b-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-eXmiqs-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/vagrant/test-mysql-connector/include/site/python2.7 failed with error code 1 in /tmp/pip-Ln020b-build
Storing debug log for failure in /home/vagrant/.pip/pip.log
```

Suggested fix:
diff --git a/lib/cpy_distutils.py b/lib/cpy_distutils.py
index e1dc75b..459dc61 100644
--- a/lib/cpy_distutils.py
+++ b/lib/cpy_distutils.py
@@ -24,9 +24,15 @@
 """Implements the DistUtils command 'build_ext'
 """

-from distutils.command.build_ext import build_ext
-from distutils.command.install import install
-from distutils.command.install_lib import install_lib
+try:
+    from setuptools.command.build_ext import build_ext
+    from setuptools.command.install import install
+    from setuptools.command.install_lib import install_lib
+except ImportError:
+    from distutils.command.build_ext import build_ext
+    from distutils.command.install import install
+    from distutils.command.install_lib import install_lib
+
 from distutils.errors import DistutilsExecError
 from distutils.util import get_platform
 from distutils.dir_util import copy_tree
[28 Feb 2016 2:08] Kuthair Habboush
We have issues with mysql python driver every time we upgrade Python.

The switch to NoSQL is more appealing everyday.
[28 Feb 2016 18:08] M B
FYI, I submitted a fix for this last year, but Oracle refused to indemnify me. In lay terms, that means they're happy to take all the rights to my patch, but they don't want to protect me against any lawsuit for its use. Thanks, but no thanks. (See https://github.com/mysql/mysql-connector-python/pull/9.)
[21 Mar 2016 8:13] Chiranjeevi Battula
Hello M B,

Thank you for the bug report.
I could not repeat the issue at my end using Connector / Python 2.1.3 but not seeing any issues with pip install .

Thanks,
Chiranjeevi.
[21 Mar 2016 8:13] Chiranjeevi Battula
Output:
chiran@chiran-VirtualBox:~$ git clone https://github.com/mysql/mysql-connector-python.git mysql-mysql-connector-python
Cloning into 'mysql-mysql-connector-python'...
remote: Counting objects: 1560, done.
remote: Total 1560 (delta 0), reused 0 (delta 0), pack-reused 1560
Receiving objects: 100% (1560/1560), 671.23 KiB | 386.00 KiB/s, done.
Resolving deltas: 100% (913/913), done.
Checking connectivity... done.
chiran@chiran-VirtualBox:~$ python -m virtualenv ./test-mysql-connector
New python executable in /home/chiran/test-mysql-connector/bin/python
Installing setuptools, pip, wheel...done.
chiran@chiran-VirtualBox:~$ ./test-mysql-connector/bin/pip install ./mysql-mysql-connector-python
Processing ./mysql-mysql-connector-python
Building wheels for collected packages: mysql-connector-python
  Running setup.py bdist_wheel for mysql-connector-python ... done
  Stored in directory: /home/chiran/.cache/pip/wheels/f5/be/85/93730a01bffd6773af3f903548cca2d0a1e5b2c134fc9e9fbb
Successfully built mysql-connector-python
Installing collected packages: mysql-connector-python
Successfully installed mysql-connector-python-2.1.3
chiran@chiran-VirtualBox:~$
[21 Mar 2016 15:27] Kuthair Habboush
pip install mysql-connector-python doesn't work:

Could not find a version that satisfies the requirement mysql-connector-python (from versions: )
No matching distribution found for mysql-connector-python

=================================================

Here's what I get when I try to run:

pip install -v mysql-connector-python-rf

Collecting mysql-connector-python-rf
  1 location(s) to search for versions of mysql-connector-python-rf:
  * https://pypi.python.org/simple/mysql-connector-python-rf/
  Getting page https://pypi.python.org/simple/mysql-connector-python-rf/
  Looking up "https://pypi.python.org/simple/mysql-connector-python-rf/" in the cache
  Current age based on date: 8
  Freshness lifetime from max-age: 600
  Freshness lifetime from request max-age: 600
  The response is "fresh", returning cached response
  600 > 8
  Analyzing links from page https://pypi.python.org/simple/mysql-connector-python-rf/
    Found link https://pypi.python.org/packages/source/m/mysql-connector-python-rf/mysql-connector-python... (from https://pypi.python.org/simple/mysql-connector-python-rf/), version: 2.0.4
    Found link https://pypi.python.org/packages/source/m/mysql-connector-python-rf/mysql-connector-python... (from https://pypi.python.org/simple/mysql-connector-python-rf/), version: 2.1.3
  Using version 2.1.3 (newest of versions: 2.0.4, 2.1.3)
  Looking up "https://pypi.python.org/packages/source/m/mysql-connector-python-rf/mysql-connector-python..." in the cache
  Current age based on date: 3960233
  Freshness lifetime from max-age: 31557600
  The response is "fresh", returning cached response
  31557600 > 3960233
  Using cached mysql-connector-python-rf-2.1.3.tar.gz
  Downloading from URL https://pypi.python.org/packages/source/m/mysql-connector-python-rf/mysql-connector-python... (from https://pypi.python.org/simple/mysql-connector-python-rf/)
  Running setup.py (path:/private/var/folders/zg/9yy3x6yj1n9fzdbmcqfk4vcr0000gn/T/pip-build-57b04n1n/mysql-connector-python-rf/setup.py) egg_info for package mysql-connector-python-rf
    Running command python setup.py egg_info
    running egg_info
    creating pip-egg-info/mysql_connector_python_rf.egg-info
    writing pip-egg-info/mysql_connector_python_rf.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/mysql_connector_python_rf.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/mysql_connector_python_rf.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/mysql_connector_python_rf.egg-info/SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'pip-egg-info/mysql_connector_python_rf.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'pip-egg-info/mysql_connector_python_rf.egg-info/SOURCES.txt'
  Source in /private/var/folders/zg/9yy3x6yj1n9fzdbmcqfk4vcr0000gn/T/pip-build-57b04n1n/mysql-connector-python-rf has version 2.1.3, which satisfies requirement mysql-connector-python-rf from https://pypi.python.org/packages/source/m/mysql-connector-python-rf/mysql-connector-python...
Installing collected packages: mysql-connector-python-rf
  Running setup.py install for mysql-connector-python-rf: started
    Running command /Users/kuthair/Code/saas-tracking/.api2.env/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/private/var/folders/zg/9yy3x6yj1n9fzdbmcqfk4vcr0000gn/T/pip-build-57b04n1n/mysql-connector-python-rf/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/zg/9yy3x6yj1n9fzdbmcqfk4vcr0000gn/T/pip-tyjshiqd-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/kuthair/Code/saas-tracking/.api2.env/include/site/python3.5/mysql-connector-python-rf
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: option --single-version-externally-managed not recognized
    Running setup.py install for mysql-connector-python-rf: finished with status 'error'
Cleaning up...
  Removing source in /private/var/folders/zg/9yy3x6yj1n9fzdbmcqfk4vcr0000gn/T/pip-build-57b04n1n/mysql-connector-python-rf
Exception information:
Traceback (most recent call last):
  File "/Users/kuthair/Code/saas-tracking/.api2.env/lib/python3.5/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/Users/kuthair/Code/saas-tracking/.api2.env/lib/python3.5/site-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Users/kuthair/Code/saas-tracking/.api2.env/lib/python3.5/site-packages/pip/req/req_set.py", line 732, in install
    **kwargs
  File "/Users/kuthair/Code/saas-tracking/.api2.env/lib/python3.5/site-packages/pip/req/req_install.py", line 884, in install
    spinner=spinner,
  File "/Users/kuthair/Code/saas-tracking/.api2.env/lib/python3.5/site-packages/pip/utils/__init__.py", line 718, in call_subprocess
    % (command_desc, proc.returncode, cwd))
pip.exceptions.InstallationError: Command "/Users/kuthair/Code/saas-tracking/.api2.env/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/private/var/folders/zg/9yy3x6yj1n9fzdbmcqfk4vcr0000gn/T/pip-build-57b04n1n/mysql-connector-python-rf/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/zg/9yy3x6yj1n9fzdbmcqfk4vcr0000gn/T/pip-tyjshiqd-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/kuthair/Code/saas-tracking/.api2.env/include/site/python3.5/mysql-connector-python-rf" failed with error code 1 in /private/var/folders/zg/9yy3x6yj1n9fzdbmcqfk4vcr0000gn/T/pip-build-57b04n1n/mysql-connector-python-rf/
[22 Mar 2016 14:01] M B
This should not be closed. Even if there are particular versions of pip that provide a work-around, not all platforms will provide those versions. Please reproduce with an earlier version of pip. MySQL Connector should provide the correct implementation. Please reopen and fix as indicated.
[28 Apr 2016 7:06] Chiranjeevi Battula
Hello M B,

Thank you for your feedback.
Verified as described.

Thanks,
Chiranjeevi.
[28 Apr 2016 7:07] Chiranjeevi Battula
log

Attachment: 79766.log (application/octet-stream, text), 8.11 KiB.

[28 Apr 2016 7:12] Chiranjeevi Battula
http://bugs.mysql.com/bug.php?id=81203 marked as duplicate of this one.
[19 Jul 2017 9:28] Ben Vercammen
I get the same error, trying to install connector version 2.1.6
Python 3.5.3
setuptools 36.2.0
pip 9.0.1

  Running setup.py install for mysql-connector-python ... error
    Complete output from command c:\python35\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\...\\AppData\\Local\\Temp\\pip-ov24xcmj-build\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\...\AppData\Local\Temp\pip-e3w05c0h-record\install-record.txt --single-version-externally-managed --compile:
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: option --single-version-externally-managed not recognized

    ----------------------------------------
Command "c:\python35\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\...\\AppData\\Local\\Temp\\pip-ov24xcmj-build\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\...\AppData\Local\Temp\pip-e3w05c0h-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\...\AppData\Local\Temp\pip-ov24xcmj-build\
[28 Apr 2022 15:13] Nuno Mariz
Posted by developer:
 
An old version of setuptools or Python is being used. Please install the latest version of setuptools. If you still get the error, install wheel as well.

pip install --upgrade setuptools
pip install --upgrade wheel
[6 May 2022 22:19] Philip Olson
It also appears this general topic was addressed in 8.0.22 when the C/Py build system was rewritten:

MySQL Connector/Python 8.0.22 Release Note:
---
Refactored the Connector/Python build system by removing artifacts of old
implementations, improved debugging, and now statically link the C
extensions. This also exposes the distutils commands, to allow the
end-user build packages.
---

The MySQL team is sorry for this delayed response, thank you for the bug report.