Creating virtualenv using altinstall - python

I have just done a fresh install of Linux Mint 17.3. It comes with both python 2.7 and 3.4. I usually work with multiple versions of python so I just do an altinstall and then for each project I create a virtualenv using the desired version of python. However im running into issues with the newly installed OS. First a few things i've already done following the install:
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install python-virtualenv
sudo apt-get install python-pip
I did an altinstall of python3.3.5:
downloaded the source tarball
./configure --with-zlib
sudo make
sudo make altinstall
I then tried creating a virtualenv in a new folder to test:
virtualenv -p python3.3 venv
This gave an error:
no module named zlib
I've had this issue in the past, so I did:
sudo apt-get install python-dev
sudo apt-get install zlib1g-dev
Now when I create the virtualenv the zlib error is gone, however im getting a new error and I can't seem to figure out how to fix it:
Running virtualenv with interpreter /usr/local/bin/python3.3
Using base prefix '/usr/local'
New python executable in venv/bin/python3.3
Also creating executable in venv/bin/python
Installing setuptools, pip, wheel...
Complete output from command /home/vega/Documents...8/venv/bin/python3.3 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/__init__.py", line 15, in <module>
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/vcs/subversion.py", line 9, in <module>
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/index.py", line 30, in <module>
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/wheel.py", line 35, in <module>
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 14, in <module>
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/compat.py", line 66, in <module>
ImportError: cannot import name HTTPSHandler
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 2363, in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 832, in main
symlink=options.symlink)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 1004, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 969, in install_wheel
'PIP_NO_INDEX': '1'
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 910, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/vega/Documents...8/venv/bin/python3.3 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 1
I read somewhere that this might have something to do with openssl so I did:
sudo apt-get install openssl
sudo apt-get install libcurl4-openssl-dev
No luck, still having the same issue.

I let someone else do the work, so I don't have to worry about building alterante versions myself from source.
I've had really good luck using Felix Krull's "deadsnakes" PPA for installing alternate Pythons on Ubuntu. Would this work for Mint 17? (based on Ubuntu Trusty)
'deadsnakes PPA' packages versions of Python: 2.3, 2.4, 2.5, 2.6, 2.7, 3.1, 3.2, 3.3, 3.4, 3.5 ... all available to install from apt. Once installed, You can manage versions and dependencies with virtualenv and pip.
Installing Python 3.5 from deadsnakes PPA:
$ sudo add-apt-repository ppa:fkrull/deadsnakes
$ sudo apt-get update
$ sudo apt-get install python3.5 python3.5-dev
The PPA maintainer has maintained these for quite a long time and updates with each Ubuntu release.
https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes

Related

Pip is not working for Python 3.10 on Ubuntu

I am new to using Ubuntu and Linux in general. I just attempted to update Python by using sudo apt-get install python3.10. When I run python3.10 -m pip install <library name> I always receive the following error:
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
sys.exit(_main())
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand
File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 15, in <module>
from pip._internal.index.package_finder import PackageFinder
File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21, in <module>
from pip._internal.index.collector import parse_links
File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
from pip._vendor import html5lib, requests
ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)```
I have tried doing sudo apt-get install python3.10-html5lib it downloaded something but it did not fix the error. How should I fix this error?
This is likely caused by a too old system pip version.
Install the latest with:
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
and test result
python3.10 -m pip --version
e.g.
pip 22.2.2 from <home>/.local/lib/python3.10/site-packages/pip (python 3.10)
and then test upgrade
python3.10 -m pip install --upgrade pip
e.g.
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in <home>/.local/lib/python3.10/site-packages (22.2.2)
I have tried all the answers above but nothing worked for me. My python3 version is 3.10.2.
So I need to install the appropriate version for pip.
However, I have tried
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
But didn't work so, I tried
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
This worked for me
This is an expanded version of #mirekphd's comment which gave me a solution that worked both on my laptop and on our server perfectly without messing anything up.
First step, if not already done is to add the 'deadsnakes' repository so that the latest python related software can be downloaded and kept updated.
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa
And, if you don't have Python 3.10 already installed you can do that with:
sudo apt install python3.10
And finally, to make pip work you will need to install the distutils package that's compatible with 3.10:
apt install python3.10-distutils
After that you can use pip the following way:
python3.10 -m pip _rest_of_the_pip
The above is necessary because the regular pip command will utilize the systems default python version and not 3.10.
If you use pip frequently then you can add an alias to your .bashrc file such as:
alias pip310='python3.10 -m pip'
After that you can just use it like this:
pip310 install blah
I've had this problem inside GitHub Actions. My solution was to resort to virtual environments to isolate from the rest of the system. Ensure python3.10-venv is installed and then do
python3.10 -m venv .venv
source .venv/bin/activate
pip install ...
...
deactivate
I had some issues installing pip as well
As sudo apt install python3-pip is still refering to pip3.8 (on mint Cinnamon 20.2 at least), pip needs to be installed in a other way.
With curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10, it turns out that pip is not found
ImportError: No module named 'pip._internal'
I found out that ensurepip command was built in and target the correct directory for python3.10
Running python3.10 -m ensurepip installs setuptools and pip and fix my missing pip module.
Pip can be updgraded afterwards using python3.10 -m pip install -U pip.
It also work with sudo (had some needs running pip as sudo)
At the time of writing and as stated on the following link. Python 3.10 is still unstable. Maybe it is a good idea to test what happens with python3.9 and see if the issue is in your local installation.
in any case, from a clean ubuntu (docker) installation by running (with sudo rights)
apt-get install software-properties-common
apt-get install python3.9
python3.9 --version
#
apt-get install python3.10
python3.10 --version
I got an the answers Python 3.9.5 and bash: python3.10: command not found respectively. so I guess the issue could be in the python 3.10 repository... for now.
However, apt-get install will not update directly your "default" python. You can check which are your those installations with
python --version
python3 --version
Any way, if you still want to install python3.10, perhaps the link above could help you.
Try:
pip3.10 install <package name>
Make sure you have the latest version pip and python3.10
The code for installing python and pip 3.10 for Ubuntu is all there, it's enough to swap just one line of that code, changing base image to the latest Ubuntu LTS version (that's ubuntu:focal) in the Dockerfile for the official Debian-based python 3.10 image (I used python 3.10 bullseye slim Dockerfile. Docker build took just 8 minutes, and here is proof that pip3.10 really works there:
$ docker run mirekphd/python3.10-ubuntu20.04 pip -V
Output:
pip 21.3.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
Or a more advanced example:
$ docker run -it --rm --name python3.10-ubuntu20.04 mirekphd/python3.10-ubuntu20.04:latest bash -c 'pip --version; pip install numpy --user --no-cache; pip show numpy; python -c "import numpy as np; print(np.ones(5))"'
Output:
pip 21.3.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
Collecting numpy
Downloading numpy-1.21.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.9 MB)
|████████████████████████████████| 15.9 MB 34.6 MB/s
Installing collected packages: numpy
WARNING: The scripts f2py, f2py3 and f2py3.10 are installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed numpy-1.21.4
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Name: numpy
Version: 1.21.4
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email:
License: BSD
Location: /root/.local/lib/python3.10/site-packages
Requires:
Required-by:
[1. 1. 1. 1. 1.]
Note: to upgrade pip, I just added this line (before CMD):
RUN python -m pip install --upgrade pip
I've got the same error after installing python 3.10 on Ubuntu with python 3.8 on board.
uninstall pip and install it again
sudo apt-get remove -y python3-pip
sudo apt-get install -y python3-pip
it's worked for me, but pip3.10 install modulename got the same error, and python3.10 -m pip install modulename working fine.
in my case this problem is associated to a previous conda installation... so I solve it by correcting the PATH. Since also Python3.10 & pip3 are installed in ~/.local/bin
In the worst way, I added a last line to ~/.bashrc hardcoded as follows
nano ~/.bashrc
add the last line:
export PATH=/usr/local/sbin:/sbin:/usr/sbin:/root/bin:/usr/local/bin:/usr/bin:/usr/local/games:/usr/games:/home/$USER/.local/bin
save, close and run
source .bashrc
this was not enough, because after removing Conda's paths it still left pip installed in /usr/bin I solved this by renaming this pip
cd /usr/bin
sudo mv pip kkpip
sudo mv pip3 kkpip3
done
pip3 list
Voilà!
Install python 3.10, pip and venv in Ubuntu 18|20
sudo apt update && sudo apt upgrade -y
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10
python3.10 --version
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
python3.10 -m pip --version
python3.10 -m pip install --upgrade pip
sudo apt install python3.10-venv
Create a virtual environment,
python3.10 -m venv venv3.10
source venv3.10/bin/activate

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

Installing MySQL-python

I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is sh: mysql_config: not found
Could someone advice me on what to do?
rmicro#ubuntu:~$ pip install MySQL-python
Downloading/unpacking MySQL-python
Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
Running setup.py egg_info for package MySQL-python
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/rmicro/build/MySQL-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/rmicro/build/MySQL-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command python setup.py egg_info failed with error code 1
On Ubuntu it is advised to use the distributions repository. So installing python-mysqldb should be straight forward:
sudo apt-get install python-mysqldb
If you actually want to use pip to install, which is as mentioned before not the suggested path but possible, please have a look at this previously asked question and answer: pip install mysql-python fails with EnvironmentError: mysql_config not found
Here is a very comprehensive guide by the developer: http://mysql-python.blogspot.no/2012/11/is-mysqldb-hard-to-install.html
To get all the prerequisites for python-mysqld to install it using pip (which you will want to do if you are using virtualenv), run this:
sudo apt-get install build-essential python-dev libmysqlclient-dev
You have 2 options, as described bellow:
Distribution package like Glaslos suggested:
# sudo apt-get install python-mysqldb
In this case you can't use virtualenv no-site-packages (default option)
but must use:
# virtualenv --system-site-packages myenv
Use clean virtualenv and build your own python-mysql package.
First create virtualenv:
# virtualenv myvirtualenv
# source myvirtualenv/bin/activate
Then install build dependencies:
# sudo apt-get build-dep python-mysqldb
Now you can install python-mysql
# pip install mysql-python
NOTE Ubuntu package is python-mysql*db* , python pypi package is python-mysql (without db)
yum install mysql-devel
It worked for me.
Reread the error message. It says:
sh: mysql_config: not found
If you are on Ubuntu Natty, mysql_config belongs to package libmysqlclient-dev
Python or Python3 with MySQL, you will need these. These libraries use MySQL's connector for C and Python (you need the C libraries installed as well), which overcome some of the limitations of the mysqldb libraries.
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-mysql.connector
sudo apt-get install python3-mysql.connector
find the folder: sudo find / -name "mysql_config" (assume it's "/opt/local/lib/mysql5/bin")
add it into PATH:export PATH:export PATH=/opt/local/lib/mysql5/bin:$PATH
install it again
this worked for me on python 3
pip install mysqlclient
In python3 with virtualenv on a Ubuntu Bionic machine the following commands worked for me:
sudo apt install build-essential python-dev libmysqlclient-dev
sudo apt-get install libssl-dev
pip install mysqlclient

pip install mysql-python fails with EnvironmentError: mysql_config not found

This is the error I get
(mysite)zjm1126#zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
Running setup.py egg_info for package mysql-python
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log
(mysite)zjm1126#zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
Running setup.py egg_info for package mysql-python
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log
What can I do to resolve this?
It seems mysql_config is missing on your system or the installer could not find it.
Be sure mysql_config is really installed.
For example on Debian/Ubuntu you must install the package:
sudo apt-get install libmysqlclient-dev
Maybe the mysql_config is not in your path, it will be the case when you compile by yourself
the mysql suite.
Update: For recent versions of debian/ubuntu (as of 2018) it is
sudo apt install default-libmysqlclient-dev
In Mac OS, I simply ran this in terminal to fix:
export PATH=$PATH:/usr/local/mysql/bin
This is the quickest fix I found - it adds it to the path, but I think you're better off adding it permanently (ie add it to /etc/paths) if you plan to install MySQL-python in another environment.
(tested in OSX Mountain Lion)
There maybe various answers for the above issue, below is a aggregated solution.
For Ubuntu:
$ sudo apt update
$ sudo apt install python-dev
$ sudo apt install python-MySQLdb
For CentOS:
$ yum install python-devel mysql-devel
apt-get install libmysqlclient-dev python-dev
Seemed to do the trick.
If you are on MAC
Install this globally
brew install mysql
then export path like this
export PATH=$PATH:/usr/local/mysql/bin
Than globally or in your venv whatever you like
pip install MySQL-Python
Note: globally for python3 as Mac can have both python2 & 3
pip3 install MySQL-Python
You can use the MySQL Connector/Python
Installation via PyPip
pip install mysql-connector-python
Further information can be found on the MySQL Connector/Python 1.0.5 beta announcement blog.
On Launchpad there's a good example of how to add-, edit- or remove data with the library.
For centos users:
yum install -y mysql-devel python-devel python-setuptools
then
pip install MySQL-python
If this solution doesn't work, and print gcc compile error like:
_mysql.c:29:20: error: Python.h: No such file or directory
You need to specify the path of Python.h, like this:
pip install --global-option=build_ext --global-option="-I/usr/include/python2.6" MySQL-python
I was trying to install mysql-python on an Amazon EC2 Linux instance and I had to install these :
yum install mysql mysql-devel mysql-common mysql-libs gcc
But then I got this error :
_mysql.c:29:20: fatal error: Python.h: No such file or directory
So I installed :
yum install python-devel
And that did the trick.
For anyone that is using MariaDB instead of MySQL, the solution is to install the libmariadbclient-dev package and create a symbolic link to the config file with the correct name.
For example this worked for me:
ln -s /usr/bin/mariadb_config /usr/bin/mysql_config
For Linux
this works for me
yum install python-devel mysql-devel
Try sudo apt-get build-dep python-mysqldb
OSX Mavericks
Due to changes within osx mavericks & xcode development tools you may get the error on installation
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
therefore use :
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install mysql-python
for mariadb install libmariadbclient-dev instead of libmysqlclient-dev
sudo apt-get install libmariadbclient-dev
You should install the mysql first:
yum install python-devel mysql-community-devel -y
Then you can install mysqlclient:
pip install mysqlclient
I had the same problem in the Terraform:light container. It is based on Alpine.
There you have to install mariadb-dev with:
apk add mariadb-dev
But that one is not enough because also all the other dependencies are missed:
apk add python2 py2-pip gcc python2-dev musl-dev
sometimes the error depends on the actual cause. we had a case where mysql-python was installed through the python-mysqldb debian package.
a developer who didn't know this, accidentally ran pip uninstall mysql-python and then failed to recover with pip install mysql-python giving the above error.
pip uninstall mysql-python had destroyed the debian package contents, and of course pip install mysql-python failed because the debian package didn't need any dev files.
the correct solution in that case was apt-get install --reinstall python-mysqldb which restored mysql-python to its original state.
Sequence to be followed.
pip install mysqlclient
sudo apt-get install python3-dev libmysqlclient-dev
pip install configparser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py
Then try to install the MYSQL-python again. That Worked for me
On Mac:
brew install mysql-client
locate mysql
mdfind mysql | grep bin
then add to path
export PATH=$PATH:/usr/local/Cellar/mysql-client/8.0.23/bin/
or permanently
echo "export PATH=$PATH:/usr/local/Cellar/mysql-client/8.0.23/bin/" >> ~/.zshrc
source ~/.zshrc
Had a similar issue trying to install on OS X Server 10.6.8. Here's what I had to do.
Using:
MySQL-python 1.2.4b4 (source)
MySQL-5.6.19 (binary installer)
Python 2.7 (binary installer)
NOTE: Installing in virtualenv...
Unzip source, open 'distribute_setup.py' and edit DEFAULT_VERSION to use the latest version of distribute tools, like so:
DEFAULT_VERSION = "0.6.49"
Save. Open 'site.cfg' file and uncomment the path to mysql_config so it looks something like (reference your own path to mysql_config):
# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /usr/local/mysql/bin/mysql_config
Now clean, build and make will not fail with the 'mysql_config' not found error.
Hope this helps someone else trying to make use of their old xserves :-)
Your sudo path does not know about your local path... go into superuser mode, add the path, and install it from there.
sudo su
export PATH=$PATH:/usr/local/mysql/bin/
pip install mysql-python
exit
And you're up and running on OSX. Now you have an updated global python.
if you install MySQL-python in your virtual env, you should check the pip version, if the version is older than 9.0.1, please update it
pip install --upgrade pip
write on 27 Aug, 2021
my macos version is BigSur(14.4), and mysql version is mysql8. It seems like in the higher version of mysql, they delete the my_config.h files but change to the mysql.h.
so your guys should run the following shell:
cd /usr/local/include/mysql
cp mysql.h my_config.h
after that, run pip install MySQL-python and everything will be ok.
on MacOS Mojave, mysql_config is found at /usr/local/bin/ rather than /usr/local/mysql/bin as pointed above, so no need to add anything to path.
In my case my database is running on container and my flask app is running on another container when i tried updating code app got broke with error
Complete output from command python setup.py egg_info:
/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-build-bya8e734/mysqlclient/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-build-bya8e734/mysqlclient/setup_posix.py", line 65, in get_config
libs = mysql_config("libs")
File "/tmp/pip-build-bya8e734/mysqlclient/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
Key in stack trace is
/bin/sh: 1: mysql_config: not found
because where my flask app is running doesn't have mysql client properly configured so first i installed mysql server and then install
sudo apt-get install mysql-server-5.7 -y
Then started MySQL
mansoor#LARC-mansur:~/Documents/clients/HR/DevopsSimulator/web$ sudo systemctl start mysql
Then install flask-mysql package and this time it worked
mansoor#LARC-mansur:~/Documents/clients/HR/DevopsSimulator/web$ sudo pip3 install flask-mysqldb
This is different case but posting here because may be someone else in the world facing same issue

Categories

Resources