0

I'm getting the following error:

from pysqlite2 import dbapi2 as sqlite ImportError: No module named pysqlite2

I tried to install it:

python -mpip install pysqlite2

I get this error:

Could not find a version that satisfies the requirement pysqlite2 (from versio ns: ) No matching distribution found for pysqlite2

i read this: ImportError: No module named pysqlite2

but the solution there is to change the code which I'm not allowed to do. This code is working on one station we simply want it to work in another station.

What should I do (I should note I'm using Windows 7)?

Community
  • 1
  • 1
avi
  • 1,626
  • 3
  • 27
  • 45

1 Answers1

3

Correct Answer

The right answer is that your code is old and it needs to be updated. Do that. Branch or fork the repository, do whatever it takes to get working, modern code.


You Can't Do The Right Thing™

If you are unable or unwilling to do such things for contrived reasons you have a few options, ranging from the least horrible to the most horrible:

  • Create your own pysqlite2 module, that is a wrapper around sqlite3. You'll probably only have to adapt a few functions, and you may not even have to do that. It might just look like this:

    import sqlite3
    
    connect = sqlite3.connect
    

    I'm not sure what features the code uses. But this would work, if you do it right.

  • Change the original code through monkeypatching. This is gnarly and error prone, and difficult to get right.

  • Change the original code by doing some AST hacks. This is difficult and hackish. You can do it. But you shouldn't. You really really shouldn't.

Just do the right thing, but if you can't, it is possible, with possibly a lot of effort, to do the wrong thing and make it work anyway. Just make sure to leave loads of comments apologizing profusely to the poor developer who comes after you and has to maintain this ball of duct tape and baling wire.

You never know, they may be a homicidal psychopath who knows where you live. (I know I'd get a little homicidal if I had to maintain code like this)

Community
  • 1
  • 1
Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
  • when you say that the code needs to be update you actually means to stop working with pysqlite2 and start working with sqlite3 ? But where can I read about the changes in order to test my code with the new package? – avi Jan 22 '17 at 13:58
  • @avi exactly. There probably aren't that many changes, if any. The dbapi spec was pretty well-defined, afaik. I would just change the name and run the code and see if it blows up. It shouldn't, but if it does, fix those spots. – Wayne Werner Jan 22 '17 at 14:35