5

When I run behave it seems to run from python2.7 and fails to find selenium, which is installed for python3.4. Do I need to configure behave to run python3.4 somewhere - I can see nothing on the behave site, or elsewhere. There are posts about using behave with python 3.4, so it is possible.

Here is what I see:

$ behave 
...
 File "/usr/local/lib/python2.7/dist-packages/behave/runner.py", line 304, in exec_file
    exec(code, globals, locals)
  File "features/steps/home_page.py", line 2, in <module>
    from selenium import webdriver
ImportError: No module named selenium

I have PYTHONPATH pointing to python 3.4/dist-packages:

$ echo $PYTHONPATH
/usr/local/lib/python3.4/dist-packages
$ ls /usr/local/lib/python3.4/dist-packages/selenium
common  __init__.py  __pycache__  selenium.py  webdriver

I have behave installed in both /usr/local/lib/pythonX.X/dist-packages where X.X is 2.7 and 3.4

Any help much appreciated.

1 Answer 1

2

If you install behave for Python 3.x and Python 2.7 each installation will install the script that starts Behave at the /usr/local/bin/behave location. Whichever is installed last will win the conflict because it will overwrite the other's file. (The files that go in /usr/local/lib/python<version>/dist-packages will be fine because <version> is different in each case.)

One way to fix this is to settle on installing Behave only on Python 3. Uninstall the Python 2.7 version and reinstall the Python 3 version, and it should work.

If you do need both versions for different projects then you should use virtualenv to create Python installations for the various projects you are working on. This is what I've settled on for my own projects.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Louis, you pointed me at the answer. I had tried uninstalling and re-installing with pip and pip3 - although there is some confusion when pip thinks behave is already installed or uninstalled with the other version. So first I just edited the shebang in the `
Thanks Louis, you pointed me at the answer. I had tried uninstalling and re-installing with pip and pip3 - although there was confusion when pip thinks behave is already installed or uninstalled with the other version (not saying who was confused, pip or me). So first I just edited the shebang in /usr/local/bin/behave to run python3 instead of python, which did the trick. Later I got the uninstall/install sequence to work and got to the same change. So you could probably just edit the shebang in behave and fix the problem. Thanks so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.