Error while installing flask-mysqldb on ubuntu 20.04 - python

I am building a flask project and I want to use MySQL database. I need flask-mysqldb as an ORM for that. So as a good practice, I created a virtual environment, install flask and other dependencies, and then for installing flask-mysqldb, I used pip install flask-mysqldb. This suddenly gives me bunch of errors. At first I realized, I dont have MySQL installed on my system. So even after installing it these errors won't go away. I also tried pip install Flask-MySQLdb don't know how this is different from the first command but same errors.
I tried searching for errors online regarding flask-mysqldb, but most of them relate to some mysql.h file error which doesn't show in my terminal logs.
(env) ck#ck-IdeaPad-Gaming-3-15ARH05:~/projects/opensoft/roomAlloc$ pip install Flask-MySQLdb
Collecting Flask-MySQLdb
Using cached Flask-MySQLdb-0.2.0.tar.gz (2.1 kB)
Requirement already satisfied: Flask>=0.10 in ./env/lib/python3.8/site-packages (from Flask-MySQLdb) (2.0.2)
Collecting mysqlclient
Using cached mysqlclient-2.1.0.tar.gz (87 kB)
ERROR: Command errored out with exit status 1:
command: /home/ck/projects/opensoft/roomAlloc/env/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bra67idg/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bra67idg/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-bra67idg/mysqlclient/pip-egg-info
cwd: /tmp/pip-install-bra67idg/mysqlclient/
Complete output (15 lines):
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-bra67idg/mysqlclient/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-install-bra67idg/mysqlclient/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-bra67idg/mysqlclient/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
mysql_config --version
mariadb_config --version
mysql_config --libs
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Please help me out, you can comment if you need more information.

I had the same error 2 minutes ago and find this command to solve the problem!
sudo apt-get install libmysqlclient-dev
the just try to install again and should work fine.
Credits:
I found this command here (In Spanish):
https://programmerclick.com/article/1483761552/

Related

Unable to install mysqlclient on ubuntu using pip

I have a following problem. I would like to install MySQLdb. I try pip install mysqlclient but I got this error message:
Collecting mysqlclient
Using cached mysqlclient-2.1.1.tar.gz (88 kB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ydedt20p/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ydedt20p/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-ydedt20p/mysqlclient/pip-egg-info
cwd: /tmp/pip-install-ydedt20p/mysqlclient/
Complete output (15 lines):
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-ydedt20p/mysqlclient/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-install-ydedt20p/mysqlclient/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-ydedt20p/mysqlclient/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
mysql_config --version
mariadb_config --version
mysql_config --libs
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
I am using Python 3.8 on Ubuntu. How can I fix it, please?
Please read and follow the installation instructions for Linux.
For Ubuntu,
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
to install the required libraries before attempting to
pip install mysqlclient

Unable to deploy Flask App in AWS ElasticBeanstalk

I am deploying a flask app in the Elastic Beanstalk environment in AWS. It works completely fine in my local, but when I upload the same to Beanstalk, I get the following error in the Log Files.
[ERROR] An error occurred during execution of command [app-deploy] - [InstallDependency]. Stop running the command. Error: fail to install dependencies with requirements.txt file with error Command /bin/sh -c /var/app/venv/staging-LQM1lest/bin/pip install -r requirements.txt failed with error exit status 1. Stderr: ERROR: Command errored out with exit status 1:
command: /var/app/venv/staging-LQM1lest/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-tu8sxhxj/mysqlclient_f51fe93483714a68ae43574db1c80ed5/setup.py'"'"'; __file__='"'"'/tmp/pip-install-tu8sxhxj/mysqlclient_f51fe93483714a68ae43574db1c80ed5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-abr_xfaw
cwd: /tmp/pip-install-tu8sxhxj/mysqlclient_f51fe93483714a68ae43574db1c80ed5/
Complete output (15 lines):
/bin/sh: mysql_config: command not found
/bin/sh: mariadb_config: command not found
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-tu8sxhxj/mysqlclient_f51fe93483714a68ae43574db1c80ed5/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-install-tu8sxhxj/mysqlclient_f51fe93483714a68ae43574db1c80ed5/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-tu8sxhxj/mysqlclient_f51fe93483714a68ae43574db1c80ed5/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
mysql_config --version
mariadb_config --version
mysql_config --libs
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/3c/df/59cd2fa5e48d0804d213bdcb1acb4d08c403b61c7ff7ed4dd4a6a2deb3f7/mysqlclient-2.0.3.tar.gz#sha256=f6ebea7c008f155baeefe16c56cd3ee6239f7a5a9ae42396c2f1860f08a7c432 (from https://pypi.org/simple/mysqlclient/) (requires-python:>=3.5). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement mysqlclient==2.0.3
ERROR: No matching distribution found for mysqlclient==2.0.3
2021/04/04 16:02:21.681275 [INFO] Executing cleanup logic
2021/04/04 16:02:21.681366 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed to install application dependencies. The deployment failed.","timestamp":1617552141,"severity":"ERROR"},{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1617552141,"severity":"ERROR"}]}]}
My requirements.txt file is as below:
aniso8601==8.0.0
click==7.1.2
Flask==1.1.2
Flask-JWT==0.3.2
Flask-MySQLdb==0.2.0
Flask-RESTful==0.3.8
Flask-SQLAlchemy==2.4.3
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
mysqlclient==2.0.3
PyJWT==1.4.2
pytz==2020.1
six==1.15.0
SQLAlchemy==1.3.18
Werkzeug==1.0.1
Even when I tried doing pip install -r requirements.txt for the first time in my local, I faced the same issue.
However, I resolved it using the following steps
1. $ brew install mysql
2. $ pip install mysqlclient
I assume something similar needs to be done in the server. Can someone help me figure out how can this be run in the server?

Unable to install bsddb3 Python package on macOS Catalina 10.15.4

I've used Homebrew to install berkeley-db and am now struggling to install the bsddb3 Python package. Any help would be much appreciated.
bash-3.2$ BERKELEYDB_DIR=/usr/local/Cellar/berkeley-db/18.1.32_1 pip install bsddb3
Collecting bsddb3
Using cached bsddb3-6.2.7.tar.gz (437 kB)
ERROR: Command errored out with exit status 1:
command: /Users/ryonlife/.local/share/virtualenvs/peg-scrapy-pegbot-ndRdHu61/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/00/9r872f810sz481x6k9pqkldw0000gn/T/pip-install-03k5olgq/bsddb3/setup.py'"'"'; __file__='"'"'/private/var/folders/00/9r872f810sz481x6k9pqkldw0000gn/T/pip-install-03k5olgq/bsddb3/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/00/9r872f810sz481x6k9pqkldw0000gn/T/pip-install-03k5olgq/bsddb3/pip-egg-info
cwd: /private/var/folders/00/9r872f810sz481x6k9pqkldw0000gn/T/pip-install-03k5olgq/bsddb3/
Complete output (8 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/00/9r872f810sz481x6k9pqkldw0000gn/T/pip-install-03k5olgq/bsddb3/setup.py", line 42, in <module>
import setup3
File "/private/var/folders/00/9r872f810sz481x6k9pqkldw0000gn/T/pip-install-03k5olgq/bsddb3/setup3.py", line 354, in <module>
db_ver = (int(fullverstr[0]), int(fullverstr[2]))
ValueError: invalid literal for int() with base 10: '.'
Trying to use the Berkeley DB you specified...
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
The trick for me was using Homebrew to install berkeley-db#4, rather than berkeley-db.
brew install berkeley-db#4
BERKELEYDB_DIR=$(brew --prefix berkeley-db#4) pip install bsddb3
Do not report this issue to Homebrew/brew or Homebrew/core!
Error: You are using macOS 11.1.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this pre-release version.

pip3 install mysql-python is failing on Mac

There are a lot of similar question but all of them has different solution. And none of them work for me.
I'm trying to install Mysql connector for Django project but it gives below error.
First I have installed latest version of Django.
Then install mysql with below code
brew install mysql - Worked fine.
Then this is the code which I'm trying install connector.
pip3 mysql-python. Was using easy_install mysql-python before but both of them are not working.
Python Version: 3.8.0
Django Version: 2.2.7
MySql Version: 8.0.18
pip3 mysql-python gives this error:
Collecting mysql-python
Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
ERROR: Command errored out with exit status 1:
command: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/pip-egg-info
cwd: /private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/
Complete output (7 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/setup.py", line 13, in <module>
from setup_posix import get_config
File "/private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ModuleNotFoundError: No module named 'ConfigParser'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
You're installing the wrong lib, you should be using mysqlclient.
pip install mysqlclient
I have a django project on my Mac using it.
Edit
You should be using virtualenv when installing pip packages.
This command worked for me
pip3 install mysqlclient==1.4.2.post1

Cannot install pattern module in python on windows ubuntu

I am trying to import a python module called pattern in my code. However, when I run:
pip install pattern
I get the following output:
Collecting pattern
Using cached
https://files.pythonhosted.org/packages/1e/07/b0e61b6c818ed4b6145fe01d1c341223aa6cfbc3928538ad1f2b890924a3/Pattern-3.6.0.tar.gz
Collecting future (from pattern)
Using cached https://files.pythonhosted.org/packages/90/52/e20466b85000a181e1e144fd8305caf2cf475e2f9674e797b222f8105f5f/future-0.17.1.tar.gz
Collecting backports.csv (from pattern)
Using cached https://files.pythonhosted.org/packages/8e/26/a6bd68f13e0f38fbb643d6e497fc3462be83a0b6c4d43425c78bb51a7291/backports.csv-1.0.7-py2.py3-none-any.whl
Collecting mysqlclient (from pattern)
Using cached https://files.pythonhosted.org/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz
ERROR: Command errored out with exit status 1:
command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4Proy9/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4Proy9/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
cwd: /tmp/pip-install-4Proy9/mysqlclient/
Complete output (12 lines):
sh: 1: mysql_config: not found
sh: 1: mariadb_config: not found
sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-4Proy9/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "setup_posix.py", line 61, in get_config
libs = mysql_config("libs")
File "setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (_mysql_config_path,))
EnvironmentError: mysql_config not found
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
I already have mysql installed and I've tried installing mysqlclient as well. I am not sure what to do!
To build/install mysqlclient you will need mysqlclient libraries and header files. To determine their location mysqlclient needs to call mysql_config script (which was not found).
You need to install mysql client library. (e.g. libmysqlclient-dev). Also make sure that mysql_config script is in your path.

Categories

Resources