title: DLL not found after switching from Python 3.7.6 to Python 3.10.3
body: <p>I am trying to upgrade a library to Python 3.10. Up to now, I have been using 3.7.6.</p>
  <p>In my library, I am using DLLs. In the package <code>__init__.py</code>, I add the DLL path to the PATH variable. Since I want to have the code compatible with 32 and 64 bit systems, I check the bitness at runtime and add the appropriate DLL folder to the PATH:</p>
  <pre><code>import os
  import sys
  
  # Add libs to PATH environment variable such that DLLs can be loaded.
  # Load either x64 or x86 depending on whether we are running a 32/64
  # bit system.
  package_directory = os.path.dirname(os.path.abspath(__file__))
  if sys.maxsize &gt; 2**32:
      path_dir = os.path.join(package_directory, 'libs', 'x64')
  else:
      path_dir = os.path.join(package_directory, 'libs', 'x86')
  
  os.environ['PATH'] += os.pathsep + path_dir
  </code></pre>
  <p>The corrresponding folder structure is</p>
  <pre><code>package_root
  |- libs
     |- x64
        |- libbristolpolled.dll
        ...
     |- x86
        |- libbristolpolled.dll
        ...
  </code></pre>
  <p>Then in a sub-package, I am using:</p>
  <pre><code>from ctypes import CDLL
  
  dll = &quot;libbristolpolled.dll&quot;
  _lib_bristlp = CDLL(dll)
  </code></pre>
  <p>This has worked fine in 3.7.6 but fails in 3.10.3 with the following error message:</p>
  <pre><code>  File &quot;C:\...\lib\site-packages\optoMD\sensor\optical\bristol\dll_api.py&quot;, line 37, in &lt;module&gt;
      _lib_bristlp = CDLL(dll)  # The correct DLL
    File &quot;C:\Program Files\Python310\lib\ctypes\__init__.py&quot;, line 374, in __init__
      self._handle = _dlopen(self._name, mode)
  FileNotFoundError: Could not find module 'libbristolpolled.dll' (or one of its dependencies). Try using the full path with constructor syntax.
  </code></pre>
  <p>If I instead use the absolute path, as the error message suggests, it works:</p>
  <pre><code>from ctypes import CDLL
  
  dll = r&quot;C:\...\libs\x64\libbristolpolled.dll&quot;
  _lib_bristlp = CDLL(dll)
  </code></pre>
  <p>What is the reason the old method doesn't work anymore, or how can I make it work again? I'd prefer not to have absolute paths in my code and I liked the fact that I handle the DLL path once in the init file and afterwards I just need to import the DLL using the file name.</p>