Answer a question

I'm trying to write a script that connects to a MySQL database. Using Python 2.7 on Ubuntu 16.04.

I don't care how it's done, I just want it done. After doing some research, I found MySQLdb to be a good package to download to connect to MySQL through python.

I've found a number of step-by-step tutorials for installing mysqldb with seemingly varying commond prompt commands (which makes little sense to me). Here's an example of one I just tried following:

https://web.archive.org/web/20180115170236/http://www.palaeopi.org.uk/index.php/how-to-connect-to-a-mysql-database-using-python-part-1/

When I try to run step 3, I get:

Reading package lists... Done

E: Unable to find a source package for python-mysqldb

...which makes me think some package lists on the OS are out of date?

I looked at this page:

https://www.tutorialspoint.com/python/python_database_access.htm

and tried running

$ sudo apt-get install python-pip python-dev libmysqlclient-dev

but get

Reading package lists... Done

Building dependency tree

Reading state information... Done

Package libmysqlclient-dev is not available, but is referred to by another package.

This may mean that the package is missing, has been obsoleted, or is only available from another source

Package python-dev is not available, but is referred to by another package.

This may mean that the package is missing, has been obsoleted, or is only available from another source

However the following packages replace it:

python

E: Package 'python-dev' has no installation candidate

E: Package 'libmysqlclient-dev' has no installation candidate

Answers

This question probably should have been posted in "Unix & Linux" or "Ask Ubuntu"

Anyway, per this post, I used Ubuntu Sources List Generator to regenerate my /etc/apt/sources.list file by checking all the boxes under "Ubuntu Branches" and "Ubuntu Updates" and clicking "Generate List" at the bottom.

Then copied & pasted the output to my sources.list file and ran: sudo apt-get update

After doing that, the following commands were successful:

sudo apt-get install python-pip python-dev libmysqlclient-dev

sudo apt-get install python-mysqldb

Logo

Ubuntu 社区为您提供最前沿的新闻资讯和知识内容

更多推荐