Troubles installing mysqlclient with pip3 - python

I'm trying to set up a python 3.6 environment with Django. The installation instructions say I should install mysqlclient to be able to connect to mySQL. I get this:
dennis#django:~$ sudo -H pip3 install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.10.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-4jiw3hvk/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-4jiw3hvk/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-4jiw3hvk/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 /tmp/pip-build-4jiw3hvk/mysqlclient/
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
mySQL is properly installed. What should be in the mysql_config file?
When I try to upgrade pip3 I get this:
dennis#django:~$ sudo -H pip3 install --upgrade pip3
Collecting pip3
Could not find a version that satisfies the requirement pip3 (from versions: )
No matching distribution found for pip3
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
After installing mysqlclient with pip3, I noticed that the module was installed in the python3.5 directory instead of in the python3.6 directory so when I tried to import the MySQLdb module running python3.6, it was not found
dennis#django:~/python_db$ python
Python 3.6.0+ (default, Feb 4 2017, 11:11:46)
[GCC 5.4.1 20161202] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'MySQLdb'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'MySQLdb'
>>>
I then reran using python 3.5 and it was found. How do I install modules using pip3 into the 3.6 directory?

If you're using Mac OS, try this:
brew install mysql
If you're using Ubuntu14/16, try this:
sudo apt install libmysqlclient-dev
and one more:
pip3 can be updated with sudo pip3 install -U pip

LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient

In my case the issue was solved by doing the following:
sudo aptitude install libmysqlclient-dev
As I was using Python 3.x, the following was also necessary:
sudo aptitude install python3-dev

If you're running MAMP on OSX, do this:
export PATH=$PATH:/Applications/MAMP/Library/bin

In Debian Stretch the required package name seems to have changed to default-libmysqlclient-dev
https://packages.debian.org/stretch/default-libmysqlclient-dev

you can try this to install mysql to a particular python directory, for example w/ python 3.6
sudo python3.6 /usr/bin/pip3 install mysqlclient

Looking over this old question (while looking for something else), I observe that the problem could be that the directory containing mysql_config was not in the current $PATH. Apparently that's what the install script uses to try to find it. It's possible for "mysql to be installed," but not on the $PATH – or for the $PATH to refer to the wrong version.

Related

Not able to install django-allauth in ubuntu 18.04.6 LTS

I'm trying to add social authentication in my project but when I try to install django-allauth it is giving me error I've tried this post but no luck it's giving me another error related to setuptools_rust I've given commands I've tried and errors related to each command.
$ pip3 install django-allauth
Error :
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-7e3fgl32/cryptography/setup.py", line 14, in
from setuptools_rust import RustExtension
ModuleNotFoundError: No module named 'setuptools_rust'
=============================DEBUG ASSISTANCE==========================
If you are seeing an error here please try the following to
successfully install cryptography:
Upgrade to the latest pip and try again. This will fix errors for most
users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
=============================DEBUG ASSISTANCE==========================
---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in
/tmp/pip-build-7e3fgl32/cryptography/
Then I tried to install setuptools_rust as it causing error
$ pip3 install setuptools_rust
This package does not give me any error it installed successfully
Then I've tried to install some commands from this post
$ sudo apt-get install build-essential libssl-dev libffi-dev python-dev
It did not change anything check response of command
Reading package lists...
Done Building dependency tree
Reading state information... Done
build-essential is already the newest version (12.4ubuntu1).
libffi-dev is already the newest version(3.2.1-8).
python-dev is already the newest version (2.7.15~rc1-1).
libssl-dev is already the newest version (1.1.1-1ubuntu2.1~18.04.14).
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
and finally I've tried this command
$ pip3 install cryptography
Error :
Collecting cryptography
Using cached https://files.pythonhosted.org/packages/f9/4b/1cf8e281f7ae4046a59e5e39dd7471d46db9f61bb564fddbff9084c4334f/cryptography-36.0.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "/tmp/pip-build-yp90u93b/cryptography/setup.py", line 54, in <module>
rust_version=">=1.41.0",
File "/home/dev/Ankit/new/afterlife_env/lib/python3.6/site-packages/setuptools/__init__.py", line 152, in setup
_install_setup_requires(attrs)
File "/home/dev/Ankit/new/afterlife_env/lib/python3.6/site-packages/setuptools/__init__.py", line 142, in _install_setup_requires
dist = MinimalDistribution(attrs)
File "/home/dev/Ankit/new/afterlife_env/lib/python3.6/site-packages/setuptools/__init__.py", line 134, in __init__
distutils.core.Distribution.__init__(self, filtered)
File "/home/dev/Ankit/new/afterlife_env/lib/python3.6/site-packages/setuptools/dist.py", line 457, in __init__
for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
AttributeError: module 'pkg_resources' has no attribute 'iter_entry_points'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/pip-build-yp90u93b/cryptography/setup.py", line 88, in <module>
version = pkg_resources.get_distribution(dist).version
AttributeError: module 'pkg_resources' has no attribute 'get_distribution'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-yp90u93b/cryptography/setup.py", line 89, in <module>
except pkg_resources.DistributionNotFound:
AttributeError: module 'pkg_resources' has no attribute 'DistributionNotFound'
=============================DEBUG ASSISTANCE=============================
If you are seeing a compilation error please try the following steps to
successfully install cryptography:
1) Upgrade to the latest pip and try again. This will fix errors for most
users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
2) Read https://cryptography.io/en/latest/installation/ for specific
instructions for your platform.
3) Check our frequently asked questions for more information:
https://cryptography.io/en/latest/faq/
4) Ensure you have a recent Rust toolchain installed:
https://cryptography.io/en/latest/installation/#rust
Python: 3.6.9
platform: Linux-4.15.0-166-generic-x86_64-with-Ubuntu-18.04-bionic
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-yp90u93b/cryptography/
It seems pip3 install --upgrade pip not worked for me then I tried this way and it worked
python3 -m pip install --upgrade pip
Thanks to this post
for Python 3:
python3 -m pip install --upgrade pip
for Python 2:
python2 -m pip install --upgrade pip
for Python:
python -m pip install --upgrade pip

Python can not import pywifi

I have install pywifi module and it success, when I try to import pywifi,I got this error.
>>> import pywifi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/pywifi/__init__.py", line 15, in <module>
from .wifi import PyWiFi
File "/Library/Python/2.7/site-packages/pywifi/wifi.py", line 15, in <module>
from .iface import Interface
File "/Library/Python/2.7/site-packages/pywifi/iface.py", line 15, in <module>
raise NotImplementedError
NotImplementedError
someone can help me?
Which python version are you running? It might be because it is installed as a Python 3 package and you're running Python 2.7 or the opposite.
To specifically install the package for Python 3, try entering this command:
pip3 install pywifi
or
python3 -m pip install pywifi
To specifically install the package for Python 2, try entering this command:
pip2 install pywifi
or
python -m pip install pywifi
I got similar errors, from the error message, I tried to install those packages that pywifi seemed to depend on, i.e., I ran
pip install comtypes
pip install iface
then it worked.

Python pip package RequestsDependencyWarning when installing elastic-search-curator

I installed elastic search curator via the following command.
sudo pip install -U elasticsearch-curator
It all installed OK.
However now when I do the following
curator_cli --version
I get the following dependency warning.
/usr/local/lib/python2.7/dist-packages/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
warnings.warn(warning, RequestsDependencyWarning)
curator_cli, version 5.5.4
How do I either fix the warning or hide it?
So took a couple of things for me to get this working.
First I upgraded cyptography as per Mufeeds suggestion
sudo pip install --upgrade cryptography
This then gave me a new error everytime I did pip <any command>
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/__init__.py", line 42, in <module>
from pip._internal import cmdoptions
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/cmdoptions.py", line 16, in <module>
from pip._internal.index import (
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/index.py", line 15, in <module>
from pip._vendor import html5lib, requests, six
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py", line 86, in <module>
from pip._vendor.urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 118, in <module>
SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
Resolved this by resintalling PyOpenSSL
sudo python -m easy_install --upgrade pyOpenSSL
Curator is now working as expected without the warnings
curator_cli --version
> curator_cli, version 5.5.4
This 1st step below will update cryptography, but break pyopenssl.
sudo pip install --upgrade cryptography
We can fix that by removing the pyopennssl library and use pip to reinstall.
sudo rm -rf /usr/lib/python2.7/dist-packages/OpenSSL
sudo rm -rf /usr/lib/python2.7/dist-packages/pyOpenSSL-0.15.1.egg-info
sudo pip install pyopenssl --upgrade
sudo pip install cryptography --upgrade
The last line will produce an error if the open sll library were to still be broken, so this validates all should be well...
My preference is to avoid another package manage like easy install in the mix, so sharing this in case that is anyone else's preference as well.

ImportError: No module named urllib3 when installing pip

I have an issue with virtualenvwrapper that requires reinstalling pip as the first step, and I am getting a strange complaint about urllib3:
$ python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 19177, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
File "/tmp/tmppQTQty/pip.zip/pip/__init__.py", line 16, in <module>
File "/tmp/tmppQTQty/pip.zip/pip/vcs/mercurial.py", line 9, in <module>
File "/tmp/tmppQTQty/pip.zip/pip/download.py", line 39, in <module>
File "/tmp/tmppQTQty/pip.zip/pip/_vendor/requests/__init__.py", line 61, in <module>
File "/tmp/tmppQTQty/pip.zip/pip/_vendor/requests/packages/__init__.py", line 29, in <module>
ImportError: No module named urllib3
when I search the pip file get-pip.py, I don't see any reference to urllib3.
I have python2.6, py2.7, and py3.4 on the machine
cchilders:~/Downloads
$ which python
/usr/local/bin/python
cchilders:~/Downloads
$ which pip
/usr/local/bin/pip
cchilders:/usr/local/bin
$ ls
2to3 easy_install-2.7 ipython pip3 smtpd.py
celery fop ipython2 pip3.5 uncompyle2
celerybeat grunt jsonlint pydoc virtualenv
celeryd idle pbr python virtualenv-clone
celeryd-multi ipdb pip python2.6 virtualenvwrapper_lazy.sh
charm iptest pip2 python2.6-config virtualenvwrapper.sh
easy_install iptest2 pip2.7 python-config
Python is defaulting to 2.6.9 which isn't what I want:
cchilders:/usr/bin
$ python
Python 2.6.9
I do not have anaconda on the machine, which caused someone else's problem. Any advice what to do now appreciated, thank you
Very first you should to know what default python version you are using then, suppose if you are using python2.7 then try to find installed pip packages under that python version using pip freeze or pip freeze | grep -i urllib3
i guess urllib3 is not installed
wget https://pypi.python.org/packages/3b/f0/e763169124e3f5db0926bc3dbfcd580a105f9ca44cf5d8e6c7a803c9f6b5/urllib3-1.16.tar.gz#md5=fcaab1c5385c57deeb7053d3d7d81d59
tar xvf urllib3-1.16.tar.gz && cd urllib3-1.16/
python setup.py install

Installation of pysftp via pip failed (because of 2 python2.x versions?)

My Ubuntu 10.04 came with Python 2.6. Now, I also installed Python 2.7, which is the system default now because when I start python from the terminal, it starts python 2.7.
Now, I want to install the library pysftp using pip, but I'm having a hard time doing so. Below follow some results of my attempts and conclusions. I did pip install pysftp, but it says the following:
Downloading/unpacking pysftp
Running setup.py egg_info for package pysftp
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/usr/local/lib/python2.6/dist-packages/setuptools/__init__.py", line 12, in <module>
from setuptools.extension import Extension
File "/usr/local/lib/python2.6/dist-packages/setuptools/extension.py", line 8, in <module>
from .dist import _get_unpatched
File "/usr/local/lib/python2.6/dist-packages/setuptools/dist.py", line 21, in <module>
packaging = pkg_resources.packaging
AttributeError: 'module' object has no attribute 'packaging'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/usr/local/lib/python2.6/dist-packages/setuptools/__init__.py", line 12, in <module>
from setuptools.extension import Extension
File "/usr/local/lib/python2.6/dist-packages/setuptools/extension.py", line 8, in <module>
from .dist import _get_unpatched
File "/usr/local/lib/python2.6/dist-packages/setuptools/dist.py", line 21, in <module>
packaging = pkg_resources.packaging
AttributeError: 'module' object has no attribute 'packaging'
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in ./pip-log.txt
It seems to me that pip (which was obviously installed before Python 2.7 was installed) links to the old version of Python, which doesn't support pysftp. Also because when I do pip --version it says:
pip 0.3.1 from /usr/lib/python2.6/dist-packages (python 2.6)
When I do whereis python, it gives me the following information:
python: /usr/src/Python-2.7.10/python /usr/bin/python2.6 /usr/bin/python /etc/python2.6 /etc/python /usr/lib/python2.6 /usr/lib/python3.1 /usr/lib64/python2.6 /usr/lib64/python3.1 /usr/local/bin/python2.7-config /usr/local/bin/python /usr/local/bin/python2.7 /usr/local/lib/python2.6 /usr/local/lib/python2.7 /usr/include/python2.6 /usr/share/python /usr/share/man/man1/python.1.gz
How can I install pysftp?
You need to reinstall pip for Python 2.7, then run pip2.7 install pysftp. You need a pip installation for each version of Python you want to use it with. The setuptools package is probably the easiest way to get going; you can simply run the following to do it all in one fell swoop:
wget https://bootstrap.pypa.io/ez_setup.py -O --no-check-certificate - | sudo python2.7 && sudo easy_install-2.7 pip && sudo pip2.7 install pysftp
Sometimes older Linux installs have issues with the above command, due to an "invalid" certificate encounted while downloading the full setuptools package via ez_setup.py (see here for more details). This can be circumvented with this alternative one-fell-swoop command:
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-18.8.1.zip --no-check-certificate && unzip setuptools-18.8.1.zip && cd setuptools-18.8.1 && sudo python setup.py install && sudo easy_install-2.7 pip && sudo pip2.7 install pysftp
I think you need to install some sort of 'essentials package' using the code
sudo apt-get install build-essential libssl-dev libffi-dev python-dev
Then you can install :
sudo pip install pysftp
sudo pip install enum

Categories

Resources