0

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 1

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

This is equivalent to pip install python-mysqldb?
Yes it is. Of course you need pip installed on the machine ;)
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)_
So actually, the package you mentioned was not the pip name of the package, I changed it to 'MySQL-python'.
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)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.