2

I'm using macOS Sierra. When importing builtwith I get these following error:

Daniels-MacBook-Pro:~ Daniel$ python
Python 3.5.2 |Anaconda 4.2.0 (x86_64)| (default, Jul  2 2016, 17:52:12) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import builtwith
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/danielotero/anaconda3/lib/python3.5/site-packages/builtwith/__init__.py", line 43
    except Exception, e:
                    ^
SyntaxError: invalid syntax

What I can do to import it correctly?

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Daniel
  • 383
  • 1
  • 4
  • 17
  • 1
    Use a version of the module that is compatible with the version of Python you're using. – kindall Nov 30 '16 at 01:44
  • 1
    `except Exception, e:` is no longer valid syntax in python 3. – rassar Nov 30 '16 at 01:44
  • 1
    So, that module doesn't support Python 3. If you put it there yourself, make sure you set it up to use the Python 2 interpreter. If you installed it with Pip or the like, file a bug report with the library in question. – Paul Becotte Nov 30 '16 at 01:45
  • @PaulBecotte how can I file a bug report? I install the module with `pip install` – Daniel Nov 30 '16 at 01:50
  • I'm certain the author is already well aware of the lack of python 3 support. You can look [here](https://bitbucket.org/richardpenman/builtwith/issues) for the issue tracker. If you want you can raise an issue there, although its likely nothing will happen unless you provide a patch yourself. – Paul Rooney Nov 30 '16 at 01:58
  • Right, not saying they aren't aware that it doesn't work, saying that `pip3 install builtwith` should probably not do anything at all instead of installing a broken package. – Paul Becotte Nov 30 '16 at 02:00

2 Answers2

3

This is because the builtwith package you installed is developed by Python2, not Python3. So it uses print and Exception as Python2 does. It also uses urllib2 library which is seperated into two part of urllib library in Python3.
It's better to use Python2 (Python2.7) to finish the work or you have to modify the source code of builtwith, that is, change all print statement into print() function, change except Exception, e into except Exception as e, and change all urllib2 functions into functions in urllib.requests and urllib.error.

Hou Lu
  • 3,012
  • 2
  • 16
  • 23
2

According to the module's issue tracker, it is not compatible with Python 3. The project owner says

This module was built with Python 2 in mind. Patches are welcome to also support Python 3, however would need to maintain backwards compatibility.

Since they don't appear to want to port it to Python 3 in order to remain backwards compatible, you should either use Python 2, look for another library, or attempt to port it yourself.

Erik Godard
  • 5,930
  • 6
  • 30
  • 33