Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python behave running from python2.7 rather than python3.4

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.

like image 849
MikeJ Avatar asked Oct 30 '22 03:10

MikeJ


1 Answers

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.

like image 139
Louis Avatar answered Dec 20 '22 01:12

Louis