1

I use WinSW for a Uvicorn service which basically provides an interface from which users can call certain SQL queries.

I have written a batch file which starts the program which works without a problem on manual execution with double clicking it. But if I run it as a service with WinSW and then start a query, there is output the error message:

ImportError: DLL load failed while importing _sqlite3: The specified module could not be found.

How can it be that the same .bat file works in standalone, but not as a service? And how do I fix it?

My service XML file with {Path_to_bat_directory} being a placeholder here in this post and being in real the hard coded directory path to the batch file containing the account name:

<configuration>
<id>X</id>
<name>X</name>
<description> XXX </description>
<executable>C:\Users\{Path_to_bat_directory}\StartUvicorn.bat</executable>
<onfailure delay="10 sec" action="restart"/>
<onfailure delay="20 sec" action="restart"/>
<onfailure action="none"/>
<resetfailure>1 hour</resetfailure>
<workingdirectory>C:\Users\{Path_to_bat_directory}</workingdirectory>
<priority>Normal</priority>
<stoptimeout>15 sec</stoptimeout>
<stopparentprocessfirst>true</stopparentprocessfirst>
<startmode>Automatic</startmode>
<waithint>15 sec</waithint>
<sleeptime>1 sec</sleeptime>
<logpath>C:\Users\{Path_to_bat_directory}\logs</logpath>
<log mode="roll"> </log>
</configuration>

The batch file StartUvicorn.bat:

call %~dp0win_env/Scripts/activate.bat
uvicorn main:app --port 8590 --host 0.0.0.0

The full error output as written into a log file is:

Exception in thread {X}:
Traceback (most recent call last):
  File "{Path}\scoop\apps\anaconda3\current\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "{Path}\scoop\apps\anaconda3\current\lib\threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "{Path}\Sources\{Project}\.\populate_cache.py", line 25, in query_failures_from_db
    df = pd.read_sql(statement, con, params=[date_from, date_to])
  File "{Path}\Sources\{Project}\win_env\lib\site-packages\pandas\io\sql.py", line 563, in read_sql
    pandas_sql = pandasSQL_builder(con)
  File "{Path}\Sources\{Project}\win_env\lib\site-packages\pandas\io\sql.py", line 744, in pandasSQL_builder
    import sqlite3
  File "{Path}\scoop\apps\anaconda3\current\lib\sqlite3\__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "{Path}\scoop\apps\anaconda3\current\lib\sqlite3\dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: DLL load failed while importing _sqlite3: The specified module could not be found.
Mofi
  • 46,139
  • 17
  • 80
  • 143
Manuel
  • 649
  • 5
  • 22

0 Answers0