"OSError: mysql_config not found" when trying to "pip install mysqlclient" - Django - pip

I'm relatively new to Django, and Web Development in general.
I am trying to
pip install mysqlclient
in my
virtualenv -p python3
to hook up Django 2.0 to mySQL. However, I'm getting this error:
Collecting mysqlclient
Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/
I have looked around for answers for hours, and yes, I have checked out this and this but nothing seems to be working.
Any help would be much appreciated!

the python package "mysqlclient" is depended on C system library to drive mysql connect,if you on ubuntu 16.4, just do as below:
sudo apt-get install libmysqlclient-dev
sudo pip install mysqlclient

If you get OSError: mysql_config not found when installing the mysqlclient Python package in macOS, then just do:
brew install mysql-client
export PATH="/usr/local/opt/mysql-client/bin:$PATH"
and retry.

You should start with cloning the mysqlclient repo:
git clone https://github.com/PyMySQL/mysqlclient-python
Then you will have to get mysql-connector-c. You can get it by doing:
brew install mysql-connector-c
Then open /usr/local/bin/mysql_config in a text editor.
From the Github issue:
There are lines in mysql_config like following:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
It should be:
#Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
Save that file and change back to the directory where you downloaded the repo. Now open site.cfg file.
uncomment the line (remove the #)
#mysql_config = /usr/local/bin/mysql_config
Save that and run:
python3 setup.py install

For CentOS here's what made it work for me:
yum install gcc mysql-devel openssl-devel
#Install library explicitly, otherwise the python3 setup.py install will fail
pip3 install "mysqlclient==2.0.3" --global-option=build_ext --global-option="-L/usr/lib64/mysql/"

Related

ModuleNotFoundError: No module named 'talib'

Cannot install ta-lib on MacOS.
pip install ta-lib
How to install it?
Try:
brew install ta-lib
pip install ta-lib
Source: https://github.com/enigmampc/catalyst/issues/187#issuecomment-374552524
Faced the issue on Big sur again
The situation:
brew install ta-lib was successful and so was pip install TA-Lib
version 0.4.19
On console:
>>> import talib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'talib'`
Solution: Installing from source worked for me, here are the steps
Install ta-lib using homebrew brew install ta-lib, this is required
Download the source from TALIB_SOURCE
untar/unzip the download ( tar -xvzf mrjbq7-ta-lib-TA_Lib-0.4.19-19-g5eb3fa4.tar.gz
cd into the folder and run:
pip install -r requirements.txt
python setup.py install
import talib should be working now
Here is the solution that usually works for me. In the file you are trying to import the module copy and paste the following code and run it. Then you will be ready to go.
from pip._internal import main as install
install(["install","ta-lib"])
Hope this will work for you, Good luck.

DLVM - pip install error

Trying to pip install on Azure Deep Learning VM is giving this error-
Complete output from command python setup.py egg_info:
ERROR:root:Error parsing
Traceback (most recent call last):
File "/anaconda/envs/py35/lib/python3.5/site-packages/pbr/core.py", line 111, in pbr
attrs = util.cfg_to_args(path, dist.script_args)
File "/anaconda/envs/py35/lib/python3.5/site-packages/pbr/util.py", line 267, in cfg_to_args
wrap_commands(kwargs)
File "/anaconda/envs/py35/lib/python3.5/site-packages/pbr/util.py", line 569, in wrap_commands
cmdclass = ep.resolve()
File "/anaconda/envs/py35/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg/pkg_resources/__init__.py", line 2264, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named 'setuptools.command.build_clib'
error in setup command: Error parsing /tmp/pip-build-9ucgxr1d/cliff/setup.cfg: ImportError: No module named 'setuptools.command.build_clib'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-9ucgxr1d/cliff/
Given the paths above it appears this is happenning on the Python 3.5 (py35) conda environment on the Linux edition of the Azure Data Science VM (DSVM) and Deep Learning VM (DLVM).
Based on the error message, the general guidance to resolve this is to update the setuptools and then try to install the library.
The commands to do that on the DSVM/DLVM on the global py35 conda environment is:
sudo /anaconda/envs/py35/bin/pip install --upgrade setuptools
sudo /anaconda/envs/py35/bin/pip install <<package name>>
For the root (Python 2.7) environment on the DSVM the commands are:
sudo /anaconda/bin/pip install --upgrade setuptools
sudo /anaconda/bin/pip install <<package name>>
Hope this resolves the issue.

How can I install Ansible on Raspbian?

I would like to install Ansible on my Raspberry Pi (raspbian/jessie) so that I can maintain it. Unfortunately, I don't seem to be able to install it. I've tried APT and PIP so far but each has a hurdle.
APT
pi#retropie:~ $ sudo apt-add-repository ppa:ansible/ansible
Traceback (most recent call last):
File "/usr/bin/apt-add-repository", line 167, in <module>
sp = SoftwareProperties(options=options)
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 105, in __init__
self.reload_sourceslist()
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 595, in reload_sourceslist
self.distro.get_sources(self.sourceslist)
File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 89, in get_sources
(self.id, self.codename))
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Raspbian/jessie
PIP (Python 2.7.9, pip 1.5.6)
pi#retropie:~ $ sudo pip install ansible
Downloading/unpacking ansible
Downloading ansible-2.4.1.0.tar.gz (6.7MB): 6.7MB downloaded
no previously-included directories found matching 'ticket_stubs'
no previously-included directories found matching 'hacking'
Downloading/unpacking jinja2 (from ansible)
Downloading Jinja2-2.9.6-py2.py3-none-any.whl (340kB): 340kB downloaded
Downloading/unpacking PyYAML (from ansible)
Downloading PyYAML-3.12.tar.gz (253kB): 253kB downloaded
Running setup.py (path:/tmp/pip-build-bsUTB2/PyYAML/setup.py) egg_info for package PyYAML
Downloading/unpacking paramiko (from ansible)
Downloading paramiko-2.3.1-py2.py3-none-any.whl (182kB): 182kB downloaded
Downloading/unpacking cryptography (from ansible)
Downloading cryptography-2.1.2.tar.gz (441kB): 441kB downloaded
Running setup.py (path:/tmp/pip-build-bsUTB2/cryptography/setup.py) egg_info for package cryptography
error in cryptography setup command: Invalid environment marker: python_version < '3'
Complete output from command python setup.py egg_info:
error in cryptography setup command: Invalid environment marker: python_version < '3'
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-bsUTB2/cryptography
Storing debug log for failure in /root/.pip/pip.log
Python 3
As you can see from the above error, "cryptography" indicates it needs > python3
I looked at the installation requirements and found that you need python 3.5+ if you use 3. Rasbian comes with 3.4...
I then tried to get python 3.6 installed using a couple of ppa's (ppa:jonathonf/python-3.6 and ppa:deadsnakes/ppa) but there aren't distros available for raspbian/jessie either.
After that I started looking at pulling down and compiling python from source but I'm expecting I'll hit another hurdle.
Ugh...
In summary, does anyone have any ideas how I can get Ansible installed on a Raspberry Pi?
Slightly old question but its the first result that comes up when googling for how to install Ansible on Raspbian so thought I'd update it. If you're running stretch (or stretch-lite)
You can just do
sudo apt-get install ansible
However currently the version of Ansbile in the Raspbian repositories is 2.2 which is a little old
Following instructions (with a little modification to overcome some errors) from the Ansible installation page you can do the following:
First run
sudo apt-get install dirmngr
Edit your /etc/apt/sources.list and append
deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main
then run
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
sudo apt-get update
sudo apt-get install ansible
This will give you version 2.7.8 as of today.
Edited to include missing command (thanks SpacePope) and correct formatting.
Jessie was released in 2015 and is officially obsolete. Stretch is the current Raspbian repo, and it has python3.5 without adding PPAs.
You can then simply install Ansible with pip3.

Install Tensorflow from source

I'm trying to install tensorflow on a cluster (I have no sudo rights).
If I try to use pip I first set the environment variable:
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
and then I execute:
pip install --upgrade $TF_BINARY_URL -b=/home/js668623/tools/tensorflow
The output is:
You are using pip version 7.1.0, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting tensorflow==0.9.0 from https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
Using cached https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
Collecting six>=1.10.0 (from tensorflow==0.9.0)
Using cached six-1.10.0-py2.py3-none-any.whl
Collecting protobuf==3.0.0b2 (from tensorflow==0.9.0)
Using cached protobuf-3.0.0b2-py2.py3-none-any.whl
Collecting wheel (from tensorflow==0.9.0)
Using cached wheel-0.29.0-py2.py3-none-any.whl
Collecting numpy>=1.8.2 (from tensorflow==0.9.0)
Using cached numpy-1.11.1.zip
Collecting setuptools (from protobuf==3.0.0b2->tensorflow==0.9.0)
Using cached setuptools-23.1.0-py2.py3-none-any.whl
Installing collected packages: six, setuptools, protobuf, wheel, numpy, tensorflow
Found existing installation: six 1.9.0
Uninstalling six-1.9.0:
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 223, in main
status = self.run(options, args)
File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 308, in run
strip_file_prefix=options.strip_file_prefix,
File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 640, in install
requirement.uninstall(auto_confirm=True)
File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 726, in uninstall
paths_to_remove.remove(auto_confirm)
File "/usr/lib/python2.7/site-packages/pip/req/req_uninstall.py", line 125, in remove
renames(path, new_path)
File "/usr/lib/python2.7/site-packages/pip/utils/__init__.py", line 314, in renames
shutil.move(old, new)
File "/usr/lib64/python2.7/shutil.py", line 299, in move
rmtree(src)
File "/usr/lib64/python2.7/shutil.py", line 252, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "/usr/lib64/python2.7/shutil.py", line 250, in rmtree
os.remove(fullname)
OSError: [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/six-1.9.0-py2.7.egg-info/PKG-INFO'
If you don't have sudo rights on the machine, personally I find the "virtualenv" installation easiest. It should just work without root access.
https://www.tensorflow.org/versions/r0.9/get_started/os_setup.html#virtualenv-installation
You might also look into the "anaconda" installation, but I have no experience with that.
If you also need a specific version of python, you 'll need more than the script I give you, but with a little bit of diggig, that script should work for you ;)
module load Python/2.7.11-foss-2016a
curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py --user --upgrade
rm get-pip.py
.local/bin/pip install --user --upgrade pip
git clone https://github.com/tensorflow/tensorflow
git clone https://github.com/bazelbuild/bazel.git
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-linux-x64.tar.gz
tar -xf jdk*
rm jdk*.gz
cd bazel
export JAVA_HOME=~/jdk1.8.0_92/
module unload GCC/4.9.3-2.25
module load GCC/4.8.2
./compile.sh
cd ../tensorflow
export PATH=/home/ulg/sysmod/gmath/bazel/output/:$PATH
./configure
bazel build -c opt //tensorflow/tools/pip_package:build_pip_package 2>/dev/null
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
cd
.local/bin/pip install --user --upgrade /tmp/tensorflow_pkg/tensorflow-0.8.0-py2-none-any.whl

Assertion error from 'pip list' in virtualenv.

Pip list is throwing an Assertion error and I'm not sure how to resolve. This has just happened after building 2 packages (PyUblas-2013.1 and boost_1_54_0) from source. I am using virtualenv.
Error below;
(virtenv)[user#xyz ~]$ pip list
beautifulsoup4 (4.2.1)
biopython (1.61)
distribute (0.6.35)
methylpy (0.1.0)
MySQL-python (1.2.4)
numpy (1.7.1)
pip (1.4)
py (1.4.15)
pytest (2.3.5)
PyUblas (2013.1)
Exception:
Traceback (most recent call last):
File "/home/user/virtenv/lib/python2.7/site-packages/pip/basecommand.py", line 134, in main
status = self.run(options, args)
File "/home/user/virtenv/lib/python2.7/site-packages/pip/commands/list.py", line 80, in run
self.run_listing(options)
File "/home/user/virtenv/lib/python2.7/site-packages/pip/commands/list.py", line 127, in run_listing
self.output_package_listing(installed_packages)
File "/home/user/virtenv/lib/python2.7/site-packages/pip/commands/list.py", line 136, in output_package_listing
if dist_is_editable(dist):
File "/home/user/virtenv/lib/python2.7/site-packages/pip/util.py", line 347, in dist_is_editable
req = FrozenRequirement.from_dist(dist, [])
File "/home/user/virtenv/lib/python2.7/site-packages/pip/__init__.py", line 194, in from_dist
assert len(specs) == 1 and specs[0][0] == '=='
AssertionError
Can anyone help me troubleshoot???
Thanks,
I think it is because the distribute package is out of date. Certainly the following fixed it for me:
pip install --upgrade distribute
Your pip may be outdated. Even in Ubuntu 14.04 LTS, the pip version it installed using apt-get install python-pip was 1.5.4. Try updating pip manually, and possibly the new packages again as well.
pip --version # 1.5.4
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
pip --version # 6.0.8
https://pip.pypa.io/en/latest/installing.html
I know it's old but since I had the same problem and the fix didn't helped. Guess does not harm adding my solution.
Just updated pip, from inside of my virtualenv.
pip install --upgrade pip

Resources