In all currently supported versions of Ubuntu open the terminal and run:
sudo apt-get install python3-bs4
python3-bs4 is an error-tolerant HTML parser for Python 3. You can see from this that there are two different packages: python-bs4 (for Python 2.x) and python3-bs4 (for Python 3.x), and to prevent you from getting confused there are also two different Integrated Development Environments for Python: IDLE and IDLE 3 to run them in.
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.
Best Answer
I dont have Ubuntu system right now with me. but still I can help you I think.
open your terminal and type as
If you find it like its available then you can install it from
that is the most preferred way.
Now how to use matplotlib with python 3. I have posted a question also in here about how to use python2 and python3 side by side.
Simple , use
python3 <filename.py>
while executing your program with python3-matplotliband similarly if you use python2 then it will load python 2.
hope that helps.