Pythons 2 and 3 live very happily next to each other on most Ubuntu installations. What you're describing (python3
mapping to a Python 2 binary) is not normal at all.
python
needs to be mapped through to Python 2 by default. There are various scripts that aren't Python 3 compliant (it's not backwards compatible) so if you break the mapping from python
, you break the system.
You're already seeing that from packages' postinst scripts that expect Python 2.
Here's how my python
is mapped (a 14.04 install):
$ readlink -f $(which python)
/usr/bin/python2.7
So let's just remap /usr/bin/python
back there:
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python{2.7,}
Then run your sudo apt-get -f install
which should now be able to run without error.
If you've knackered things so badly, you might find yourself in the position where you need to manually unpack the Python packages into your system (they're just zips with header data).
If you've just munched /usr/bin/python2.7
(which should be the Python 2 binary) you can replace this by downloading the python2.7-minimal package and extracting the binary to the right place:
apt-get download python2.7-minimal
ar x python2.7-minimal_*.deb data.tar.xz
sudo tar xJf data.tar.xz -C / './usr/bin/python2.7'
rm data.tar.xz
That's based on the current 14.04 package. If you're on another release you might have to tweak paths. Or copy from a live system running the same version of Ubuntu.
More broadly speaking, if you want a Python development environment, I seriously suggest you look at the venv
module. This is as with Py2's VirtualEnv except that it's built-in. You can install whatever you like in a non-root, non-system way and that includes mapping python
to the Python binary you pick (including Pypy).
On 14.04 there's a bug in Python 3 that needs fixing before you can create a venv, but it that can be worked-around quite easily at the moment. We just need to install ensurepip
:
wget -qO- http://d.pr/f/YqS5+ \
| sudo tar xzf - -C $(python3 -c "import sys; print(sys.path[1])") --no-same-owner
Then create and activate the venv:
python3 -m venv myvenv
source ./myvenv/bin/activate
Now you're in your own playground. You'll need to call the activate in the future (or call the myvenv/bin/python binary explicitly) to load the right Python path.
I also struggle with this error, then I found the python3-dev is missing but when I run the command it's already installed. Then I check for which python version it is installed using below command -
sudo find / -name "Python.h"
and output is like -
python2.7/Python.h
python3.5/Python.h
So then I check the version of python I am running to install that package using below command
python3 -V
Output -
Python 3.6.7
So to install python3-dev use below command
sudo apt-get install python3.6-dev
Just replace it with your python3 or python2 version
Best Answer
When
-lfoo
fails, look for packages that providelibfoo.so
.libssl.so
andlibcrypto.so
are provided bylibssl-dev
. So, installlibssl-dev
.