title: django.db.utils.OperationalError: (2013, "Lost connection to MySQL server at 'handshake: reading inital communication packet', system error: 0")
body: <p>I am developing an app in django to push it on Heroku, and while trying to migrate a database in mysql to heroku, I pip installed mysql-python and as I try to run the server, I got this error:</p>
  <blockquote>
  <p>django.db.utils.OperationalError: (2013, &quot;Lost connection to MySQL
  server at 'handshake: reading inital communication packet', system
  error: 0&quot;)</p>
  </blockquote>
  <p>(I had my virtual environment on).<br>
  The strange thing is that the package installed python even if I had that already installed.<br> I found out that it unistalled django and several modules I previously installed, even pip!<br></p>
  <p>I re-installed the modules but now as I run the server I get that error above.<br>
  If I run the server from another app directory, the database runs fine.<br>
  Is it maybe related to something I had installed in my directory and maybe was apparently overwritten by the strange package?</p>
  <p>here is my pip freeze result:</p>
  <pre><code>certifi==2019.6.16
  dj-database-url==0.5.0
  Django==2.2.3
  django-heroku==0.3.1
  gunicorn==19.9.0
  mysql-connector-python==8.0.16
  mysqlclient==1.4.2.post1
  protobuf==3.6.0
  psycopg2==2.8.3
  PyMySQL==0.9.3
  python-decouple==3.1
  pytz==2019.1
  six==1.12.0
  sqlparse==0.3.0
  whitenoise==4.1.2
  wincertstore==0.2
  </code></pre>
  <p>I will now delete the project and try to rebuild it anew, as long as I understand, what screw up the project was my attempt to install mysql-python.</p>
  <pre><code>Collecting mysql-python   Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip Building wheels for collected packages: mysql-python   Building wheel for mysql-python (setup.py) ... error   ERROR: Complete output from command 'C:\Applicazioni_Tommaso\Anaconda3\envs\met3\python.exe' -u -c 'import setuptools, tokenize;__file__='&quot;'&quot;'C:\\Users\\Tommaso\\AppData\\Local\\Temp\\pip-install-yr8h0ec1\\mysql-python\\setup.py'&quot;'&quot;';f=getattr(tokenize, '&quot;'&quot;'open'&quot;'&quot;', open)(__file__);code=f.read().replace('&quot;'&quot;'\r\n'&quot;'&quot;', '&quot;'&quot;'\n'&quot;'&quot;');f.close();exec(compile(code, __file__, '&quot;'&quot;'exec'&quot;'&quot;'))' bdist_wheel -d 'C:\Users\Tommaso\AppData\Local\Temp\pip-wheel-ywwxryy8' --python-tag cp37:   ERROR: running bdist_wheel   running build   running build_py  creating build   creating build\lib.win-amd64-3.7   copying
  _mysql_exceptions.py -&gt; build\lib.win-amd64-3.7   creating build\lib.win-amd64-3.7\MySQLdb   copying MySQLdb\__init__.py -&gt; build\lib.win-amd64-3.7\MySQLdb   copying MySQLdb\converters.py -&gt; build\lib.win-amd64-3.7\MySQLdb   copying MySQLdb\connections.py -&gt; build\lib.win-amd64-3.7\MySQLdb   copying MySQLdb\cursors.py -&gt; build\lib.win-amd64-3.7\MySQLdb   copying MySQLdb\release.py -&gt; build\lib.win-amd64-3.7\MySQLdb   copying MySQLdb\times.py -&gt; build\lib.win-amd64-3.7\MySQLdb   creating build\lib.win-amd64-3.7\MySQLdb\constants   copying MySQLdb\constants\__init__.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants   copying MySQLdb\constants\CR.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants   copying MySQLdb\constants\FIELD_TYPE.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants   copying MySQLdb\constants\ER.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants   copying MySQLdb\constants\FLAG.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants   copying MySQLdb\constants\REFRESH.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants   copying MySQLdb\constants\CLIENT.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants   running build_ext   building '_mysql' extension   creating build\temp.win-amd64-3.7   creating build\temp.win-amd64-3.7\Release   C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,2,5,'final',1)
  -D__version__=1.2.5 &quot;-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include&quot; -IC:\Applicazioni_Tommaso\Anaconda3\envs\met3\include -IC:\Applicazioni_Tommaso\Anaconda3\envs\met3\include &quot;-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include&quot; &quot;-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt&quot; &quot;-IC:\Program Files (x86)\Windows Kits\8.1\include\\shared&quot; &quot;-IC:\Program Files (x86)\Windows Kits\8.1\include\\um&quot; &quot;-IC:\Program Files (x86)\Windows Kits\8.1\include\\winrt&quot; &quot;-IC:\Program Files (x86)\Windows Kits\8.1\include\\cppwinrt&quot; /Tc_mysql.c /Fobuild\temp.win-amd64-3.7\Release\_mysql.obj /Zl   _mysql.c  
  _mysql.c(42): fatal error C1083: Non è possibile aprire il file inclusione: 'config-win.h': No such file or directory   error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2   ----------------------------------------   ERROR: Failed building wheel for mysql-python   Running setup.py clean for mysql-python Failed to build mysql-python Installing collected packages: mysql-python   Running setup.py install for mysql-python ... error
      ERROR: Complete output from command 'C:\Applicazioni_Tommaso\Anaconda3\envs\met3\python.exe' -u -c 'import setuptools, tokenize;__file__='&quot;'&quot;'C:\\Users\\Tommaso\\AppData\\Local\\Temp\\pip-install-yr8h0ec1\\mysql-python\\setup.py'&quot;'&quot;';f=getattr(tokenize, '&quot;'&quot;'open'&quot;'&quot;', open)(__file__);code=f.read().replace('&quot;'&quot;'\r\n'&quot;'&quot;', '&quot;'&quot;'\n'&quot;'&quot;');f.close();exec(compile(code, __file__, '&quot;'&quot;'exec'&quot;'&quot;'))' install --record 'C:\Users\Tommaso\AppData\Local\Temp\pip-record-dwqliwhp\install-record.txt'
  --single-version-externally-managed --compile:
      ERROR: running install
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.7
      copying _mysql_exceptions.py -&gt; build\lib.win-amd64-3.7
      creating build\lib.win-amd64-3.7\MySQLdb
      copying MySQLdb\__init__.py -&gt; build\lib.win-amd64-3.7\MySQLdb
      copying MySQLdb\converters.py -&gt; build\lib.win-amd64-3.7\MySQLdb
      copying MySQLdb\connections.py -&gt; build\lib.win-amd64-3.7\MySQLdb
      copying MySQLdb\cursors.py -&gt; build\lib.win-amd64-3.7\MySQLdb
      copying MySQLdb\release.py -&gt; build\lib.win-amd64-3.7\MySQLdb
      copying MySQLdb\times.py -&gt; build\lib.win-amd64-3.7\MySQLdb
      creating build\lib.win-amd64-3.7\MySQLdb\constants
      copying MySQLdb\constants\__init__.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants
      copying MySQLdb\constants\CR.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants
      copying MySQLdb\constants\FIELD_TYPE.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants
      copying MySQLdb\constants\ER.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants
      copying MySQLdb\constants\FLAG.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants
      copying MySQLdb\constants\REFRESH.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants
      copying MySQLdb\constants\CLIENT.py -&gt; build\lib.win-amd64-3.7\MySQLdb\constants
      running build_ext
      building '_mysql' extension
      creating build\temp.win-amd64-3.7
      creating build\temp.win-amd64-3.7\Release
      C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,2,5,'final',1)
  -D__version__=1.2.5 &quot;-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include&quot; -IC:\Applicazioni_Tommaso\Anaconda3\envs\met3\include -IC:\Applicazioni_Tommaso\Anaconda3\envs\met3\include &quot;-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include&quot; &quot;-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt&quot; &quot;-IC:\Program Files (x86)\Windows Kits\8.1\include\\shared&quot; &quot;-IC:\Program Files (x86)\Windows Kits\8.1\include\\um&quot; &quot;-IC:\Program Files (x86)\Windows Kits\8.1\include\\winrt&quot; &quot;-IC:\Program Files (x86)\Windows Kits\8.1\include\\cppwinrt&quot; /Tc_mysql.c /Fobuild\temp.win-amd64-3.7\Release\_mysql.obj /Zl
      _mysql.c
      _mysql.c(42): fatal error C1083: Non è possibile aprire il file inclusione: 'config-win.h': No such file or directory
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
      ---------------------------------------- ERROR: Command &quot;'C:\Applicazioni_Tommaso\Anaconda3\envs\met3\python.exe' -u -c 'import setuptools, tokenize;__file__='&quot;'&quot;'C:\\Users\\Tommaso\\AppData\\Local\\Temp\\pip-install-yr8h0ec1\\mysql-python\\setup.py'&quot;'&quot;';f=getattr(tokenize, '&quot;'&quot;'open'&quot;'&quot;', open)(__file__);code=f.read().replace('&quot;'&quot;'\r\n'&quot;'&quot;', '&quot;'&quot;'\n'&quot;'&quot;');f.close();exec(compile(code, __file__, '&quot;'&quot;'exec'&quot;'&quot;'))' install --record 'C:\Users\Tommaso\AppData\Local\Temp\pip-record-dwqliwhp\install-record.txt'
  --single-version-externally-managed --compile&quot; failed with error code 1 in C:\Users\Tommaso\AppData\Local\Temp\pip-install-yr8h0ec1\mysql-python\
  </code></pre>
  <hr />
  <p><strong>UPDATE</strong></p>
  <p>The bad command, that is,</p>
  <blockquote>
  <p>pip install mysql-python</p>
  </blockquote>
  <p>had set my python default path to 2.7 instead of 3.7.</p>
  <p>To fix it, I had to (Windows 10):</p>
  <p>Cortana &gt; search bar &gt; type &quot;env&quot; &gt; change environment variables for the system &gt; environment variables &gt; select &quot;Path&quot; &gt; change &gt;</p>
  <p>create and move to the top (or simply move to the top) the path in which you have installed python 3.7.</p>
  <p>Save &gt; close anaconda.
  This made pyhton and its modules work again.
  I had to reinstall pip, now it works again.
  But when my virtual environment is on, I have problems with my connected database in mysql.</p>