I'm making an installation package which is to be used on windows and includes a sqlite3 database (which is not read-only).
When then package has been installed the sqlite3 database has become read-only for some reason. By the way, I'm using python 2.7.3 (with sqlite3 lib) to read/write from it.
My question is, is there away for me to unlock the sqlite database to become read/write through a python script, bat script, or the inno setup script perhaps?
Or is there a way for me to modify my inno setup script to keep the sqlite database from becoming read-only in the first place?
I've tried searching the forums and googling for an answer but haven't succeeded in finding one.
THanks in advance!
On Windows, anything inside the Program Files folder is meant to be read-only during normal use. Data files should be installed elsewhere. See here for more advice on where to put them:
Does Microsoft have a best practices document regarding the storage of App Data vs User Data on different Windows Platforms?
Related
I created a Python package that is actually a command line interface. Everything works fine, but I would like to be able to store simple user settings (a few values) in some file (json, yaml, or whatever). Handling such files itself is not a problem, but I don't know where I could store them. My program can be installed using pip install https://github.com/repo and works fully off-line.
It seems that Python does not allow me to store settings files in the same folder, where the compiled program itself is located (Programs\Python\Python38\Scripts) which makes sense, but I don't know how to do it any other way.
Inspired by the comments under the question, I searched a little bit more and found the answer to my problem.
I store my settings file in C:\users\me\appdata\local\programs\python\python38\lib\site-packages\my_package\config.json which can be accessed with
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.json')
I haven't tested this on Linux or macOS yet, but I think it will work.
EDIT: Unfortunately it does not work on Linux without sudo. For this reason, I used the following:
os.path.join(os.path.expanduser("~"), '.my_package_name', 'config.json')
I am trying to create a database that I can then read from / write to in Python. I've tried installing the recommended dev installation via this https://dev.mysql.com/downloads/windows/installer/8.0.html. I then went into the designer and added a table with some entities. However, the UX in MySQL is really terrible and I can't work out how to actually view the table in the database I've just created and add test values or whatever. I got frustrated and uninstalled MySQL completely because either I downloaded it incorrectly (I selected dev machine but I want to develop and run it on this machine, was that the wrong option?) or it's just terrible to deal with. However, it seems like there are no real alternatives unfortunately and so I would appreciate some help with regards to just setting up a simple database and connecting it to Python so I can perform SQL statements from my Python code. Also, another complication is that my normal Python installation (i.e. the one linked to PATH etc.) is 3.6, but I was forced to install 3.7 when I downloaded MySQL so I'm not really sure how that will work.
Thanks.
I'm trying to add object-persistence to my python app. I'm currently using python 3.4 on windows.
The only module I found useful was shelve but on windows, it appears, it creates three different files rather than one: 'db.bak' ,'db.dat' and 'db.dir'.
How can I force shelve to create only single file ?
furthermore , whenever I need to open that db on read-only mode , 'db.dir' is being edited for some reason.
Does anyone know how to fix those issues ? or maybe suggest other modules that would work considering the OS and python version?
Summary:
What is the best (easiest, most flexible, simplest) way to redistribute a Firebird SQL database with Python code in a way that end users can use it without going to the trouble of installing and maintaining Firebird?
Background (somewhat long-winded):
I've been trying to write a program that sifts through stock fundamentals and appraises different companies' stock based on those fundamentals and randomized weights. I noticed that after some length of time, the program seemed to just stall. I did use multi-threading here and there, and I considered dead/livelocks, but apart from just combing through the code and seeing if it makes sense, I can't debug that. I noticed I was also eating up a lot of RAM, since all this data was held in big Python dicts in memory. So I figured putting it in SQL databases would fix that.
After a few weeks, I got the code working again with SQLAlchemy and SQLite. Now the problem is that the appraisal function takes ten minutes (!) per stock. Multiplied by a total of twelve "genomes" competing initially, this would add up to around 200 hours. I started thinking maybe this had to do with SQLite's concurrency locks, or something along those lines, so I started trying to use Firebird, since it is the only other one I know that stores a database in a file.
Question elaboration:
Ideally, I would be able to just throw my code on a disk or a server, take it to another computer with Python on it, and run everything out of the box. That's doable with SQLite. Is it possible with Firebird? I know that there is a separate embedded package for Windows, but that Linux only has the libfbembed library that ships with the Classic server. The docs said that Linux always requires some version of the Firebird server proper to be installed.
Will end users need to do any database administration to make that work; that is, will they need to set up users and such manually, as if I had just given them an fdb file and told them to figure out the rest? Or is it enough to install the basic packages for Firebird? Will I ever be able to get something close to the simplicity of SQLite in redistributing Firebird databases? Is there any special syntax I need to pass to SQLalchemy/FDB/Kinterbasedb to use an embedded server? (I could not find anything about this on either SQLalchemy or FDB's websites). Can my program run seamlessly on Linux and Windows, or will there need to be slightly different setups for each case?
Thanks in advance, anyone who can answer some of these questions.
Well, i only can give partial answers. But i think that'll be enough to start with.
Let's start with the Firebird embedded thing: As you have written - using linux as os you have to provide a full install. There is no other way.
HINT: Use the native tgz provided from firebird, not any package delivered from distribution - to avoid dependency hell.
Installing Firebird on Windows : The Windows Firebird Installer is mostly a 'click-through' thing. Luckily you can customize the installer: Install Firebird and look into doc\scripted-install.txt.
HINT: on Win7/8 don't install into %PROGRAM FILES% or %PROGRAM FILES (x86)%
Talking to firebird:
AFAIK you have two options, but for both i don't know if and how they will work with SQLAlchemy:
The fdb module which comes from firebird. When installing the fdb package make shure the appropriate fbclient.dll is in the search path.
the pyfirebirdsql module: https://github.com/nakagami/pyfirebirdsql/ which needs no dll or that. Partial drawback - it is not as fast as the fdb module as there is no real database engine. Personally i only use it for short lookups.
Using the fdb module you also can talk to the firebird services api - from creating over dropping databases to querying header statistics, ending up with backup/restore actions.
That should at least answer the question if the end user needs to perform any database administration.
I'm using Berkeley DB in a python project, and I am wondering if I can make the libraries available to python without specifically installing berkeley DB.
How can you embed Berkeley DB in an application generally?
Has anyone done this with python and bsddb3?
You can't... at least not without installing something. You'd have to statically link BDB into the python interpreter. But, then you'd have a custom python binary you'd need to install.