💾 Archived View for chirale.org › 2017-03-21_3579.gmi captured on 2024-08-18 at 17:30:27. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-05-12)
-=-=-=-=-=-=-
In the past it was difficult to get MySQL working on virtualenv without using system packages. Now you can have a real separated environment with simple steps:
Follow this guide to install virtualenv using this command:
this guide to install virtualenv
virtualenv myproject --no-site-packages
This command will install a new virtualenv inside a new directory
Activate virtualenv:
source myproject/bin/activate
Upgrade setuptools
pip install pip --upgrade
You can now install MySQLdb, inside the package MySQL-python:
pip install MySQL-python
Now do a simple test trying to connect to an existing database:
python import MySQLdb db = MySQLdb.connect(host="localhost", # your host, usually localhost user="chirale", # your username passwd="ITSASECRET", # your password db="chiraledb") # name of the database cursor = conn.cursor() cursor.execute("SELECT VERSION()") row = cursor.fetchone() print "server version:", row[0] cursor.close() conn.close()
Tested on CentOS 7, Python 7
Tip: If you are starting to create a database doing all the dirty work alone you’ve to give SQLAlchemy a try. You can use like an ORM or a lower level as you wish.
The Hitchhiker’s Guide to Python
Simple MySQLdb connection tutorial
About the same topic
Python: MySQLdb on Windows virtualenv (w. figures)
https://web.archive.org/web/20170321000000*/http://docs.python-guide.org/en/latest/dev/virtualenvs/
https://web.archive.org/web/20170321000000*/https://en.wikipedia.org/wiki/SQLAlchemy
https://web.archive.org/web/20170321000000*/http://docs.python-guide.org/en/latest/dev/virtualenvs/
https://web.archive.org/web/20170321000000*/http://stackoverflow.com/a/372899/892951