I am writing a python script for an application. The application needs python-mysqldb. In terminal, I can install it with apt-get or pip. How can I install using python script? I am using python 2.7.
1 Answer
You could use pip in a python script for installing the package
import pip
if __name__ == '__main__':
pip.main(['install', 'MySQL-python'])
Then you can run the script from a terminal.
6 Comments
Janki Chhatbar
This is equivalent to pip install python-mysqldb?
Timo Hanisch
Yes it is. Of course you need pip installed on the machine ;)
Janki Chhatbar
This is giving error.So I treid adding 'if name == 'main': pip.main(['install','libmysqlclient-dev'])'. This gave error too. So I treid 'if name == 'main': pip.main(['install','mysql-connector-python'])'. This is giving error too.._Downloading/unpacking mysql-connector-python Could not find any downloads that satisfy the requirement mysql-connector-python Some externally hosted files were ignored (use --allow-external mysql-connector-python to allow)_
Timo Hanisch
So actually, the package you mentioned was not the pip name of the package, I changed it to 'MySQL-python'.
Janki Chhatbar
Yes..tried MySQL-python. It said mysql_config not found. So searched web and it said to apt-get install libmysqlclient-dev.tried
if __name__ == __main__: pip.main(['install','libmysqlclient-dev']). then tried if __name__ == '__main__': pip.main(['install',mysql-connector-python '']).again error Could not find any downloads that satisfy the requirement mysql-connector-python Some externally hosted files were ignored (use --allow-external mysql-connector-python to allow) |