How to create a database in MySQL then link it to Python - python

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.

Related

PyCharm 2018.1 update broke new project creation

This feels like a crap question but I am too new to know what details to look for or include. I've been using python less than a month for data analysis, and was told that I would likely find the combination of Anaconda and PyCharm helpful, and I have.
Recently Pycharm was updated to 2018.1 and since then my imports on new projects don't seem to be working properly.
i.e. I use pyodbc for some data import. I literally copy pasted the code from a prior project and then installed the package (ie right click install pyodbc which completes "successful"). I am getting
"pyodbc.Error: ('HY000', 'The driver did not supply an error!')"
For giggles I built new sub scripts in the old project files and duplicated them in the new project files, they work in the old but not the new.
Any help would be appreciated.

Mac OS X + Python + Django + MySQL

I have worked many hours over several days trying to get MySQL working with Mac OS X, Python (I've tried both 2.7 and 3.3), and Django 1.6.
This topic is addressed on many webpages, both in SO and elsewhere, and over a period of many years (one solution specifically uses MySQLdb 1.2.2, which was last modified in March 2007). Some of the posts seem to say they have it working, but when I try their solution, it doesn't work for me. On the other hand, one post from a few months ago flatly says it can't be done.
The heart of the problem seems to be installing a driver (whether MySQLdb or mysql-connector), and symptoms vary depending on which instructions you follow. Typical show-stoppers from the various attempted solutions have been "No module named 'MySQLdb'" and "Symbol not found: _mysql_affected_rows" when you finally try "python manage.py syncdb".
One wonders whether the very act of trying so many solutions has itself messed up my dev environment so that what would have worked with a clean slate won't work now. Yes, I've tried this both with and without virtualenv. I don't know whether virtualenv has gotten me closer or not, because I don't know how to recognize getting closer.
I happen to have OS X 10.7.5 (Lion) and MySQL 5.0 on my machine. Those are not the latest versions of either, but I don't know whether that matters and I'm reluctant to keep changing things. They work fine for other MySQL applications on my machine. I'll gladly upgrade either or both if a solution is available for later versions.
Does anyone actually have the configuration listed as the title of this post working, with either Python 2.7 or 3.3? If so, I'd be most grateful if you'd direct me to the solution.
UPDATE
I just wanted to let readers know that I eventually did get my app running with Python 3.3, Django 1.6, and sort-of MySQL. My app has been running smoothly for months.
I'm sorry, I don't have the time to recreate the many hours of steps and mis-steps I followed to get this working. I'll just outline the key points:
I started using Macs more than a decade ago, starting with PowerBooks, so my Mac has a lot of old stuff on it. The first thing I finally decided I had to do was to get rid of every copy of Python and Django; installers such as MacPorts and Fink; and any of the directories they like to put their installations into. Google was of course invaluable to me in learning how to do this, and all the other steps mentioned below.
I then started fresh (as much as I could give my Mac a fresh start) using Homebrew as my only command-line installer.
I also used virtualenv. I don't actually understand virtualenv very well, and again don't have the time to research it, but I've got it working and it does seem to be a good idea.
Well, within virtualenv, I also used pip, which I guess is also a command-line installer, but it seems to be part of the Homebrew/virtualenv methodology. Sorry I can't provide any expertise on this.
As I mentioned, the app sort-of worked with MySQL, but when I used Homebrew to uninstall MySQL, and install MariaDB instead, it started to work really well. As far as I can tell, Django, Sequel Pro, PyCharm's DB features, and other programs that think they're talking to MySQL can't tell the difference between MySQL and MariaDB. I also really like the MariaDB online documentation. Admittedly, "MariaDB" isn't a great name, but neither is "MySQL".
Bottom line: If someone tells you it's impossible to get Python3.3 and Django1.6 running with MySQL (or at least MariaDB) on a Mac, don't believe them. It can be done, it's just hard to do if your system has a lot of legacy files and apps that can get into conflict with what you're trying to do.
One more thing: When I started work on this project, I suspended my work on a GAE app I'd been making great progress on for over a year. Since I'll be going back to that project soon, I wanted to keep my GAE install up-to-date on my machine, but sadly, I can no longer run the GAE installer for updates. I get some error about not being able to find python2.5. Sigh. That's what I'll have to look forward to solving when I get back to working on that project.
You could try using the pure-python pymysql:
sudo easy_install pymysql
(Use pip if you have it installed.) Then, add this before execute_from_command_line in manage.py:
try:
import pymysql
pymysql.install_as_MySQLdb()
except ImportError:
pass
I feel your struggle. I went through the same thing and found the setup process very frustrating. I don't really know which instructions you follow on which website that is throwing exceptions. But I find that all these instructions are missing either one or two small prerequisites. For example, xcode and command-line tools needed to be installed before doing any pip install. For the connectors, if you are using mysql-python, you probably need to install python-devel. I used this instruction. You are probably right that with so many installation attempts your system is probably corrupt and you might need to re-install your osx and start clean, again. It's painful, but that's what I had to do to make it work. I hope your next attempt works.

How to distribute a Python program with embedded Firebird SQL for Linux and Windows

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.

Inno setup makes sqlite3 database read-only

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?

django - python

I am very new to django, python and ubuntu command line. I've been installing an application on PC's and this is my third one. Ive come across this error and am not sure where else to look. When I run
python manage.py syncdb
i receive the following error
django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "winepad". GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?
Any help would be greatly appreciated
Thanks
Check Your PostGIS Version. it must be atleast 1.3.
Have you gone through this character-building documentation:
http://docs.djangoproject.com/en/dev/ref/contrib/gis/install/
?
We need to know more about versions of things and what steps you took to come to this error. Otherwise, the error is pretty informative. The database that your settings refer to must not have been created with postgis 1.3+ from a spatial database template.
I wonder since you say that you are new,, Do you realize that you are attempting to install a Django package that has geo requirements and therefore assumes that you have a correct version of postgres-sql up and running (which is a somewhat difficult install itself)
You might want to start with something simpler that just uses the sql-lite database look in the Djano settings file to see what the database setting is....

Categories

Resources