No Module Selenium in Python 3 on a Mac

3,368 views
Skip to first unread message

Marc Perez

unread,
Sep 8, 2013, 5:19:21 PM9/8/13
to obey-the-test...@googlegroups.com
Hi,
I am reading the third revision of the book that now uses python 3.

When i type python3 and try 
To import selenium: from selenium import webdriver
i get the following error:
ImportError: No module named 'selenium'


Has anyone set up the Django, selenium, and python3 on a mac successfully?

contact

unread,
Sep 8, 2013, 9:49:20 PM9/8/13
to obey-the-test...@googlegroups.com
I don't have experience on a mac, but did you install Selenium through PIP (installation instructions for PIP here)?

$ pip-3.3 install --upgrade selenium

Marc Perez

unread,
Sep 8, 2013, 10:35:29 PM9/8/13
to contact, obey-the-test...@googlegroups.com
I get "$ pip-3.3: command not found" when i type in pip-3.3 install
--upgrade selenium

When I do pip --version I get:
pip 1.4 from /Library/Python/2.7/site-packages/pip-1.4-py2.7.egg (python 2.7)

I've read a lot of tutorials about installing pip-3.3 but so far none
have worked.
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Obey the testing goat! Test-Driven Web Development with
> Python book" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/obey-the-testing-goat-book/-FrVUGPC1Ao/unsubscribe.
> To unsubscribe from this group and all of its topics, send an email to
> obey-the-testing-go...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Jason Selby

unread,
Sep 9, 2013, 12:20:45 AM9/9/13
to obey-the-test...@googlegroups.com
I think this is what i did:

Download and install python3 fro python.org website.  This creates a python3 in /usr/local/bin/.

Download the distribute module from pypi.org

Create a file in your home directory called .pydistutils.cfg (note the period at the beginning of the filename).
add the following two lines to it. 
[install]
user=true

These lines will cause python modules to be installed for your user only when installed with easy-install or pip, and you won't be required to use sudo.  Modules will be installed in Library/Python/ within your home directory.

unpack distribute and cd into the directory
python3 setup.py build
python3 setup.py install

I think this should get you the easy_install command Library/Python/3.3/bin/easy_install.

then:
~/Library/Python/3.3/bin/easy_install pip

~/Library/Python/3.3/bin/pip install selenium
~/Library/Python/3.3/bin/pip install django

I don't remember why I installed distribute first, except that the distribute module may be needed by pip.  You can add the path to pip to your path variable or create aliases/links to make using it easier.

Harry Percival

unread,
Sep 9, 2013, 9:29:14 AM9/9/13
to Jason Selby, obey-the-test...@googlegroups.com
It is definitely one of the dirty little secrets of Python that, while the language itself is a charm, and the best possible thing for beginners, the installation process, particularly of the packages manager, is a total nightmare.

My recommendation would be to install homebrew -- I'm no mac expert, but it seems pretty indispensable if you want to get any proper development done on a mac.  Once you have that installed and configured properly  (its site has good instructions, but you need to get xcode installed too), then installing things becomes as simple as "brew install"

brew install python3

I *believe* gives you python 3 *and* pip-3.3


--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
------------------------------
Harry J.W. Percival
------------------------------
Twitter: @hjwp
Mobile:  +44 (0) 78877 02511
Skype:         harry.percival

Jason Selby

unread,
Sep 9, 2013, 9:55:36 AM9/9/13
to obey-the-test...@googlegroups.com
Sorry, that should be pypi.python.org.  It's the python package index.

Marc Perez

unread,
Sep 9, 2013, 10:28:38 AM9/9/13
to obey-the-test...@googlegroups.com
Hi Jason,

Thank for the help. I tried to install everything but it didn't work.
Message has been deleted

Vic Simeone

unread,
Sep 9, 2013, 1:27:20 PM9/9/13
to obey-the-test...@googlegroups.com, contact
It looks like you're close if you have pip 1.4.1 installed because there isn't a version 3.3. However, it looks like PIP is installed against python 2.7. After my first reply to this post I tried installing PIP on a new machine and remembered how confusing it was. Read on for my procedure and some observations. 

Following the PIP installation instructions did work for me on Ubuntu 12.04:

$ sudo python3 ./ez_setup.py
$ sudo python3 ./get-pip.py

$ whereis pip
pip: /usr/local/bin/pip
 
$ ls -l /usr/local/bin/pip*
-rwxr-xr-x 1 root root 282 Sep  9 10:13 /usr/local/bin/pip
-rwxr-xr-x 1 root root 290 Sep  9 10:13 /usr/local/bin/pip-3.2
 
$ /usr/local/bin/pip --version
pip 1.4.1 from /usr/local/lib/python3.2/dist-packages (python 3.2)
$ /usr/local/bin/pip-3.2 --version
pip 1.4.1 from /usr/local/lib/python3.2/dist-packages (python 3.2) 

$ sudo pip-3.2 install --upgrade selenium
...
 
Notes & things that confuse me:
  • You must install these scripts using python 3
  • Your version of pip will be 1.4.1
  • You reference pip by Python version, not pip version - so in my case : $ pip-3.2 install --upgrade selenium because I have Python 3.2
  • I have no idea why /usr/bin/pip and pip-3.2 are different binaries... when I do pip* --version you see they both reference python 3.2

Harry Percival

unread,
Sep 10, 2013, 4:24:13 AM9/10/13
to Vic Simeone, obey-the-test...@googlegroups.com
Thanks for trying Vic, but installing stuff on a mac really isn't as easy as it is on Linux.

My recommendation is to use homebrew, if you're on a mac.  Install homebrew, configure it (it will prompt you at the command line after you install it), get xcode from the app store, and then you're good to go with

    brew install python3




--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Harry Percival

unread,
Sep 10, 2013, 12:51:15 PM9/10/13
to obey-the-test...@googlegroups.com
I've added an extra "macOs notes" box to the installation instructions.  What do you guys think?

http://chimera.labs.oreilly.com/books/1234000000754/pr01.html#_required_software_installations

Jonathan Sundqvist

unread,
Jan 7, 2014, 2:22:02 PM1/7/14
to obey-the-test...@googlegroups.com, hj...@cantab.net
I've definitely had my fights my python installs. Gettings things to work the way you want it has sometimes been an utter frustration. But installing python3 via brew works great and I couldn't recommend it more.

That said, rather than using 'pip-3.3' I use only 'pip3'. For some reason pip-3.3 doesn't work and I'm not going to figure out why. :) Pip3 works and I'm happy.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-goat-book+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
--
------------------------------
Harry J.W. Percival
------------------------------
Twitter: @hjwp
Mobile:  +44 (0) 78877 02511
Skype:         harry.percival
Reply all
Reply to author
Forward
0 new messages