python3 - No module named 'html5lib'
Asked Answered
D

1

5

I'm running a python3 program that requires html5lib but I receive the error No module named 'html5lib'.

Here are two session of terminal:

sam@pc ~ $ python
Python 2.7.9 (default, Mar  1 2015, 12:57:24) 
[GCC 4.9.2] on linux2
>>> import html5lib
>>> html5lib.__file__
'/usr/local/lib/python2.7/dist-packages/html5lib/__init__.pyc'
>>> quit()

sam@pc ~ $ python3
Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
>>> import html5lib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'html5lib'
>>> 

Where can be the problem?

Discard answered 14/4, 2016 at 9:24 Comment(0)
E
8

Seems you have the module only for python 2. Most probably need to install it for python3. Usually use pip3 for that.

pip3 install html5lib   

You can check your installed modules using:

pip freeze    (or pip3 freeze)

I strongly recommend you to use virtualenv for development. So you can separate the different python versions and libraries/Modules by project.

use:

pip3 install virtualenv   

You can then easily create "environments" using (simple version)

virtualenv projectname  --python=PYTHON_EXE_TO_USE

This creates a directory projectname. You just switch into that dir and do a

Scripts\activate (on linux/unix: source bin/activte)

And boom. You have an isolated environment with the given python.exe and no installed modules at all. You also have an isolated pip for that project. Really helps a lot.

To end working in that project do a:

Scripts\deactivate (on linux: deactivate)

Thats it.

ONe moer thing ;) You can also do a

pip freeze > requirements.txt 

to save all needed dependencies for a project in a file. Whenever you need to restart from scratch in a new virtualenv you cabn simply do a:

pip install -r requirements.txt

This installs all needed modules for you. Add a -U to get the newest version.

Excavator answered 14/4, 2016 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.