python - Can I rename pyodbc egg to odbc egg on ubuntu? -
for whatever reason dark history, have been running our system using pyodbc on windows long time now, called odbc.
now trying port linux, have installed pyodbc, long running code cannot "import odbc", though "import pyodbc" works fine.
one solution "if sys.plateform.find('linux')" , "import pyodbc odbc" or "import pyodbc" depending, seems hacky.
is there way rename egg?
i tried naively renaming 2 files , "import odbc" finds files . . . seems confused because of internal naming:
file "/local/mnt/workspace/aswp401/source/qcom/qct/modem/arch/sandbox/fmerrow/hub/py/utils/dbutils.py", line 1, in import odbc importerror: dynamic module not define init function (initodbc)
the problem of course being function named initpyodbc, not initodbc.
is there offcial way such rename? or sys.platform best option?
frank
the simplest way handle is:
try: import pyodbc except importerror: import odbc pyodbc unless there's compelling reason otherwise, don't try guess 1 installed, try them out. case of eafp—but in addition usual advantages, there's fact continue work if guesses later become invalid (e.g., because set openbsd machine, upgrade package on windows machine, …).
it's better try official current name of module first, try older/variant/etc. names fallback.
it's better use official current name throughout code… but if you've got lot of code odbc.this , odbc.that, , don't trust simple search-and-replace or other refactoring tools @ disposal, can import pyodbc odbc instead.
just renaming egg may or may not work (it looks won't in case), it's bad idea if does.
at least, confuse package manager (whether that's apt, easy_install, pip, or else). example, may not able upgrade or uninstall package, install other packages depend on it, etc.
worst of all, may "mostly" work, fail because, e.g., code buried in c extension module in middle of package relies on qualified module name, , code gets called in rare edge case of app.
Comments
Post a Comment