Reputation: 13468
>>> from selenium import webdriver
>>> browser = webdriver.PhantomJS()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'PhantomJS'
I can't seem to get this to work on OSX.
I installed selenium with pip install selenium
and I have this version:
>>> import selenium
>>> selenium.__version__
'2.21.2'
I installed PhantomJS with port install phantomjs
, and verified that it is the latest:
$ phantomjs --version
2.0.0
I checked its location is in my PATH
and my PYTHONPATH
, restarted my Terminal, etc., but this did not fix the error.
browser = webdriver.Firefox()
works fine.
EDIT:
It seems I was pointing to an old version - 2.21.2
- installed via MacPorts, but I am still unable to correct the problem.
I have got as far as:
sudo pip uninstall selenium
sudo port uninstall py-selenium
sudo port uninstall py27-selenium
And than I tried to reinstall the latest (2.45.0) from pip:
$ sudo pip install selenium
Downloading/unpacking selenium
Downloading selenium-2.45.0.tar.gz (2.6MB): 2.6MB downloaded
Running setup.py (path:/private/tmp/pip_build_root/selenium/setup.py) egg_info for package selenium
Installing collected packages: selenium
Running setup.py install for selenium
Successfully installed selenium
Cleaning up...
But now I can't even import selenium:
>>> import selenium
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named selenium
EDIT 2:
It also appears that pip is pointing to the wrong python. I changed the first line of pip to the correct path, but I'm not sure if this is what I want, and now pip just crashes when I try pip install selenium
:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.14-py2.7.egg/pkg_resources.py", line 2671, in <module>
working_set.require(__requires__)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.14-py2.7.egg/pkg_resources.py", line 654, in require
needed = self.resolve(parse_requirements(requirements))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.14-py2.7.egg/pkg_resources.py", line 552, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==1.5.6
Upvotes: 0
Views: 6984
Reputation: 13468
My problem was pip
was not pointing to the correct python installation.
First I removed all unwanted selenium installations as described in my "EDIT".
Then I removed pip with rm /usr/local/bin/pip
and did a fresh install via sudo port install py27-pip
.
Then I ran sudo pip install selenium
.
And now everything is working.
>>> import selenium
>>> selenium.__version__
'2.45.0'
>>> from selenium import webdriver
>>> browser = webdriver.PhantomJS()
>>>
Upvotes: 1