title: why does python3.6 container uses the /usr/lib of python 3.9
body: <p>I start a docker contain with</p>
  <pre><code>FROM python:3.6
  ARG DEBIAN_FRONTEND=noninteractive
  RUN apt-get update
  RUN apt-get install -y apt-utils vim curl apache2 apache2-utils
  RUN apt-get -y install libapache2-mod-wsgi-py3
  RUN pip install --upgrade pip
  RUN pip install --upgrade setuptools==57.5.0
  RUN pip install django==4.0 celery==5.2 ptvsd suds-py3 psycopg2 mysqlclient pysnmp pyparsing python-dateutil spyne lxml supervisor flower
  ADD ./site-config.conf /etc/apache2/sites-available/000-default.conf
  ADD ./www/project /var/www/html
  WORKDIR /var/www/html 
  RUN chmod 775 /var/www/html/project
  CMD [&quot;apache2ctl&quot;, &quot;-D&quot;, &quot;FOREGROUND&quot;]
  </code></pre>
  <p>And the apache file:</p>
  <pre><code>WSGIPythonPath /var/www/html/project:/usr/local/lib/python3.6/site-packages/
  
  &lt;VirtualHost *:80&gt;
      ServerName localhost
      ServerAdmin webmaster@localhost 
      DocumentRoot /var/www/html/project 
      Alias /static &quot;/var/www/html/project/static&quot;
      WSGIScriptAlias / /var/www/html/project/project/wsgi.py 
      ErrorLog /var/www/html/logs/error.log
      CustomLog /var/www/html/logs/access.log combined 
  &lt;/VirtualHost&gt;
  </code></pre>
  <p>It installs both python 3.6 and 3.9 as I noticed:</p>
  <p>All pips I installed are in 3.6 including mysqlclient</p>
  <p>But when it tries to import _mysql, it checks the /usr/lib of python3.9 which gives an error because it in 3.6 not 3.9.
  <code>File &quot;/usr/lib/python3.9/importlib/__init__.py&quot;, line 127, in import_module</code>
  <code> ImportError: cannot import name '_mysql' from partially initialized module 'MySQLdb' (most likely due to a circular import) (/usr/local/lib/python3.6/site-packages/MySQLdb/__init__.py)</code>
  Why doe this issue happen and how to prevent it?</p>
  <p>Here are the logs for the django application, I get the error:</p>
  <pre><code>[Thu Mar 10 11:19:44.400586 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972] mod_wsgi (pid=12660): Exception occurred processing WSGI script '/var/www/html/project/project/wsgi.py'., referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423410 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972] Traceback (most recent call last):, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423482 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/MySQLdb/__init__.py&quot;, line 18, in &lt;module&gt;, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423498 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     from . import _mysql, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423533 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972] ImportError: cannot import name '_mysql' from partially initialized module 'MySQLdb' (most likely due to a circular import) (/usr/local/lib/python3.6/site-packages/MySQLdb/__init__.py), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423558 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972] , referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423568 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972] During handling of the above exception, another exception occurred:, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423576 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972] , referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423594 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972] Traceback (most recent call last):, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423755 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/var/www/html/project/project/wsgi.py&quot;, line 16, in &lt;module&gt;, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423769 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     application = get_wsgi_application(), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423791 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/core/wsgi.py&quot;, line 12, in get_wsgi_application, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423802 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     django.setup(set_prefix=False), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423821 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/__init__.py&quot;, line 24, in setup, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423831 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     apps.populate(settings.INSTALLED_APPS), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423849 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/apps/registry.py&quot;, line 114, in populate, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423870 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     app_config.import_models(), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423889 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/apps/config.py&quot;, line 301, in import_models, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423899 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     self.models_module = import_module(models_module_name), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423915 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/lib/python3.9/importlib/__init__.py&quot;, line 127, in import_module, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423924 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     return _bootstrap._gcd_import(name[level:], package, level), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423939 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1030, in _gcd_import, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423958 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1007, in _find_and_load, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423976 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 986, in _find_and_load_unlocked, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.423995 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 680, in _load_unlocked, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424013 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 790, in exec_module, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424033 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 228, in _call_with_frames_removed, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424051 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/contrib/auth/models.py&quot;, line 3, in &lt;module&gt;, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424062 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424080 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/contrib/auth/base_user.py&quot;, line 48, in &lt;module&gt;, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424090 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     class AbstractBaseUser(models.Model):, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424108 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/db/models/base.py&quot;, line 122, in __new__, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424118 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     new_class.add_to_class('_meta', Options(meta, app_label)), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424143 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/db/models/base.py&quot;, line 326, in add_to_class, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424154 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     value.contribute_to_class(cls, name), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424172 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/db/models/options.py&quot;, line 207, in contribute_to_class, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424184 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424202 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/utils/connection.py&quot;, line 15, in __getattr__, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424212 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     return getattr(self._connections[self._alias], item), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424228 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/utils/connection.py&quot;, line 62, in __getitem__, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424238 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     conn = self.create_connection(alias), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424254 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/db/utils.py&quot;, line 204, in create_connection, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424264 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     backend = load_backend(db['ENGINE']), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424280 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/db/utils.py&quot;, line 111, in load_backend, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424290 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     return import_module('%s.base' % backend_name), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424306 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/lib/python3.9/importlib/__init__.py&quot;, line 127, in import_module, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424316 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     return _bootstrap._gcd_import(name[level:], package, level), referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424332 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py&quot;, line 15, in &lt;module&gt;, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424342 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     import MySQLdb as Database, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424357 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]   File &quot;/usr/local/lib/python3.6/site-packages/MySQLdb/__init__.py&quot;, line 24, in &lt;module&gt;, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424366 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972]     version_info, _mysql.version_info, _mysql.__file__, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.424418 2022] [wsgi:error] [pid 12660:tid 139881606039296] [client 172.23.0.1:43972] NameError: name '_mysql' is not defined, referer: http://localhost:8005/request/outgoing/
  [Thu Mar 10 11:19:44.495983 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984] mod_wsgi (pid=12660): Failed to exec Python script file '/var/www/html/project/project/wsgi.py'., referer: http://localhost:8005/request/search/
  [Thu Mar 10 11:19:44.496864 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984] mod_wsgi (pid=12660): Exception occurred processing WSGI script '/var/www/html/project/project/wsgi.py'., referer: http://localhost:8005/request/search/
  [Thu Mar 10 11:19:44.497096 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984] Traceback (most recent call last):, referer: http://localhost:8005/request/search/
  [Thu Mar 10 11:19:44.497253 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984]   File &quot;/var/www/html/project/project/wsgi.py&quot;, line 16, in &lt;module&gt;, referer: http://localhost:8005/request/search/
  [Thu Mar 10 11:19:44.497269 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984]     application = get_wsgi_application(), referer: http://localhost:8005/request/search/
  [Thu Mar 10 11:19:44.497292 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984]   File &quot;/usr/local/lib/python3.6/site-packages/django/core/wsgi.py&quot;, line 12, in get_wsgi_application, referer: http://localhost:8005/request/search/
  [Thu Mar 10 11:19:44.497303 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984]     django.setup(set_prefix=False), referer: http://localhost:8005/request/search/
  [Thu Mar 10 11:19:44.497321 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984]   File &quot;/usr/local/lib/python3.6/site-packages/django/__init__.py&quot;, line 24, in setup, referer: http://localhost:8005/request/search/
  [Thu Mar 10 11:19:44.497331 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984]     apps.populate(settings.INSTALLED_APPS), referer: http://localhost:8005/request/search/
  [Thu Mar 10 11:19:44.497349 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984]   File &quot;/usr/local/lib/python3.6/site-packages/django/apps/registry.py&quot;, line 83, in populate, referer: http://localhost:8005/request/search/
  [Thu Mar 10 11:19:44.497359 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984]     raise RuntimeError(&quot;populate() isn't reentrant&quot;), referer: http://localhost:8005/request/search/
  [Thu Mar 10 11:19:44.497391 2022] [wsgi:error] [pid 12660:tid 139881472829184] [client 172.23.0.1:43984] RuntimeError: populate() isn't reentrant, referer: http://localhost:8005/request/search/```
  </code></pre>