Solved

Downgrade Python 3.5 to 3.3

Posted on 2016-08-16
30
330 Views
Last Modified: 2016-11-05
In order for selenium webdriver to work with my Mac Firefox install I need Python 3.3 so Selenium 3.0 can be used.  Can anyone tell me how to downgrade my python to 3.3?

I have 2.53.6 installed now
0
Comment
Question by:sharingsunshine
  • 15
  • 14
30 Comments
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41758692
You dont need to downgrade, you can just install another version of python in your computer.
First thing: make sure you have Homebrew installed. If not, open a terminal and type this command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Open in new window


After that, you can follow the steps below:

Step 1 - Install pyenv
brew update
$ brew install pyenv

Open in new window


Step 2 - Install multiple versions of python
$ pyenv install 3.5.0
$ pyenv install 3.4.3
$ pyenv install 3.3.6
$ pyenv install 3.2.6
$ pyenv install 2.7.10
$ pyenv install 2.6.9

Open in new window


To check versions installed:
$ pyenv versions

Open in new window


To make OS X remember which version of python is running on a given folder, navigate to that folder and type:
pyenv local 3.5.0

Open in new window


Regards,
Walter.
0
 

Author Comment

by:sharingsunshine
ID: 41758722
Great instructions but how do I use them.  I typed in pyenv local 3.3.6 in the command line and then typed in idle.  I then went to another tab and then typed in

rjw sudo pip3 install selenium
Password:
The directory '/Users/rjw/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/rjw/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied (use --upgrade to upgrade): selenium in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages

Open in new window


but as you can see it reverted to the old 3.5 installation I already had.  So how do I use the homebrew python 3.3.6 and install selenium 3.0?

Also, I am not familiar with homebrew so if you can suggest a resource on how to use it.  Before this I was using macports.

Thanks,
0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41758787
Open the command line and type one by one the lines on my post.
Of course you are going to install only one version of Python.

Homebrew link:
http://brew.sh/
0
 

Author Comment

by:sharingsunshine
ID: 41759160
I have already used the command line and typed in each line one by one.

rjw pyenv versions
  system
  2.6.9
  2.7.10
  3.2.6
* 3.3.6 (set by /Users/rjw/.python-version)
  3.4.3
  3.5.0
rjw which pyenv
/usr/local/bin/pyenv

Open in new window


My question is what do I do to get selenium 3.0 with python 3.3.6?
0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41759190
Ok, here are the steps
1) move to a folder where your script is;
2) open the command line and type
pyenv local 3.3.6

Open in new window

3) Then, any command like pip that you run on this folder will be related to python 3.3.6 version:
pip install selenium

Open in new window

0
 

Author Comment

by:sharingsunshine
ID: 41759367
it is still showing 3.5

rjw touch expertsBrazil2webdriver.py
rjw nano expertsBrazil2webdriver.py
rjw pyenv local 3.3.6
rjw pip install selenium
Requirement already satisfied (use --upgrade to upgrade): selenium in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages
rjw pwd
/Users/rjw/Documents/Python

Open in new window

0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41759430
Navigate to your script folder and send the output of this command:
python -V

Open in new window


If it is not showing 3.3.6, then try this command:
pyenv rehash

Open in new window


and then rerun the first command.
0
 

Author Comment

by:sharingsunshine
ID: 41759501
still staying at 2.7

rjw cd Documents/Python
rjw pyenv rehash
rjw python -V
Python 2.7.12
rjw pyenv local 3.3.6
rjw python -V
Python 2.7.12
rjw pyenv rehash
rjw python -V
Python 2.7.12
rjw pyenv local 3.3.6
rjw python -V
Python 2.7.12

Open in new window

0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41759532
try this
[code]
pyenv activate
[/code]

then try the Python -V
0
 

Author Comment

by:sharingsunshine
ID: 41759548
rjw pyenv activate
pyenv: no such command `activate'
0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41759769
Hard one this python stuff on mac.... Ok, let's see:

1) modify (or create) ~/.bashrc to include the following text:
export PIP_REQUIRE_VIRTUALENV=true
# define a "global pip" function to use outside virtualenv:
gpip(){
    PIP_REQUIRE_VIRTUALENV="" pip "$@"
}
test -f /usr/local/bin/virtualenvwrapper.sh && source /usr/local/bin/virtualenvwrapper.sh
if which pyenv > /dev/null ; then eval "$(pyenv init -)"; fi

Open in new window

2) open a new terminal window and type:
source ~/.bash_profile

Open in new window

3) Go to your script folder and open a terminal:
pyenv local 3.3.6
gpip install virtualenv

Open in new window


4) Install pyenv-virtualenv
brew install pyenv-virtualenv

Open in new window


5) Create a virtualenv on your folder and activate it:
pyenv virtualenv 3.3.6 <name of your virtual env>
pyenv activate <name of your virtual env>
python -V

Open in new window


And the python -V should return 3.3.6

The step to activate the virtualenv will be needed everytime you open a terminal to run the script.
If you are using XCode for development, then probably it will have a way to help you to control that.
0
 

Author Comment

by:sharingsunshine
ID: 41759809
getting an error and line 3 I changed gpip to pip, hope that was correct.

rjw pyenv local 3.3.6
rjw gpip install virtualenv
-bash: gpip: command not found
rjw pip install virtualenv
Collecting virtualenv
  Downloading virtualenv-15.0.3-py2.py3-none-any.whl (3.5MB)
    100% |################################| 3.5MB 92kB/s 
Installing collected packages: virtualenv
Successfully installed virtualenv-15.0.3
rjw brew install pyenv-virtualenv
==> Auto-updated Homebrew!
Updated Homebrew from 823505a to db2e9b8.
Updated 1 tap (homebrew/core).
==> Updated Formulae
artifactory  libftdi      libpng       node-build   radare2      unrar      
==> Using the sandbox
==> Downloading https://github.com/yyuu/pyenv-virtualenv/archive/v20160716.tar.g
==> Downloading from https://codeload.github.com/yyuu/pyenv-virtualenv/tar.gz/v2
######################################################################## 100.0%
==> ./install.sh
==> Caveats
To enable auto-activation add to your profile:
  if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
==> Summary
🍺  /usr/local/Cellar/pyenv-virtualenv/20160716: 19 files, 58.8K, built in 8 seconds
rjw pyenv virtualenv 3.3.6 pyenv-virtualenv/20160716
pyenv-virtualenv: no slash allowed in virtualenv name.
rjw pyenv virtualenv 3.3.6 virtualenv-15.0.3        
Installing pip from https://bootstrap.pypa.io/get-pip.py...
Collecting pip
  Using cached pip-8.1.2-py2.py3-none-any.whl
Collecting setuptools
  Using cached setuptools-25.2.0-py2.py3-none-any.whl
Collecting wheel
  Using cached wheel-0.29.0-py2.py3-none-any.whl
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-8.1.2 setuptools-25.2.0 wheel-0.29.0
rjw pyenv activate virtualenv-15.0.3

Failed to activate virtualenv.

Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.

Open in new window

0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41759826
No, you need to follow the exact commands I gave you, otherwise, it wont work.
0
 

Author Comment

by:sharingsunshine
ID: 41759828
when I used gpip I got this error

rjw gpip install virtualenv
-bash: gpip: command not found
0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41759837
but have you executed the step 1 of my post, that was to make a change on your  ~/.bashrc ?
Because the gpip is created there. If it is not online, it will give the error.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:sharingsunshine
ID: 41759902
yes, I did

https://gyazo.com/45da6e93fbbb244b78143ea1b5052cc1

here are the contents

export PIP_REQUIRE_VIRTUALENV=true
# define a "global pip" function to use outside virtualenv:
gpip(){
    PIP_REQUIRE_VIRTUALENV="" pip "$@"
}
test -f /usr/local/bin/virtualenvwrapper.sh && source /usr/local/bin/virtualenvwrapper.$
if which pyenv > /dev/null ; then eval "$(pyenv init -)"; fi

Open in new window


does something need to be restarted?
0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41759924
In theory, you should have executed the following line after changing/creating the file with the content above.
source ~/.bash_profile

Open in new window


And just after that, execute the other commands.
0
 

Author Comment

by:sharingsunshine
ID: 41759987
Here is my history file during that command.  Maybe I missed something.  I mentioned a long time ago that I had macports installed when I added homebrew.  I have since removed it.

 501  source ~/.bash_profile
  502  cd Documents/Python
  503  ls
  504  pyenv local 3.3.6
  505  gpip install virtualenv
  506  pip install virtualenv
  507  brew install pyenv-virtualenv
  508  pyenv virtualenv 3.3.6 pyenv-virtualenv/20160716
  509  pyenv virtualenv 3.3.6 virtualenv-15.0.3
  510  pyenv activate virtualenv-15.0.3
  511  pwd
  512  cd /rjw
  513  cd rjw
  514  cd ..
  515  cd ..
  516  ls
  517  ls -la
  518  pwd
  519  ls -la
  520  nano .bashrc

Open in new window

0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41760007
Ok, so let's try something different: assuming that you have virtualenv correctly installed, execute the following steps on the terminal:
cd Documents/Python
pyenv local 3.3.6
pyenv virtualenv 3.3.6 test_env
pyenv activate test_env
python -V

Open in new window


Paste the output, please.
0
 

Author Comment

by:sharingsunshine
ID: 41760012
rjw cd Documents/Python
rjw pyenv local 3.3.6
rjw pyenv virtualenv 3.3.6 test_env
Installing pip from https://bootstrap.pypa.io/get-pip.py...
Collecting pip
  Using cached pip-8.1.2-py2.py3-none-any.whl
Collecting setuptools
  Using cached setuptools-25.2.0-py2.py3-none-any.whl
Collecting wheel
  Using cached wheel-0.29.0-py2.py3-none-any.whl
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-8.1.2 setuptools-25.2.0 wheel-0.29.0
rjw pyenv activate test_env

Failed to activate virtualenv.

Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.

rjw python -V
Python 2.7.10

Open in new window

0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41760041
Try this: before you try to activate the environment, execute this line:
eval "$(pyenv init -)"

Open in new window


Then, try to activate the environment again and type python -V.
Paste the output.

If it works, then you need to add that line in your ~/.bash_profile and restart your shell.
0
 

Author Comment

by:sharingsunshine
ID: 41760055
Great

rjw eval "$(pyenv init -)"
rjw pyenv activate test_env
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(test_env) rjw python -V
Python 3.3.6
(test_env) rjw 

Open in new window


where do I add that line top, middle, bottom

how do you restart the shell?
0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41760065
Could be at the bottom.

To restart:
exec "$SHELL"

Open in new window

0
 

Author Comment

by:sharingsunshine
ID: 41760085
perhaps I did something out of sequence it activates but shows 2.7.10

rjw nano .bashrc
rjw exec "$SHELL"
rjw source ~/.bash_profile
rjw pyenv local 3.3.6
rjw gpip install virtualenv
Requirement already satisfied (use --upgrade to upgrade): virtualenv in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages
rjw pyenv activate virtualenv-15.0.3
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(virtualenv-15.0.3) rjw python -V
Python 2.7.10

Open in new window

0
 
LVL 15

Accepted Solution

by:
Walter Ritzel earned 500 total points
ID: 41760160
Please use the virtual environment that have worked, the test_env.
It is advised that you uninstall the other environments.
Maybe uninstall all the virtual environments and install one that will work correctly.

And now that you have everything set up, the steps to create a virtualenv with the correct version of python is:
cd <path to your folder with scripts>
pyenv local <python version that you want to run on this folder>
pyenv virtualenv <python version that you want to run on this folder> <virtualenv name>
pyenv activate <virtualenv name>
... <commands to install modules, etc...>

Open in new window


Other useful commands:
deactivate environment:
pyenv deactivate

Open in new window


to list all installed environments:
pyenv virtualenvs

Open in new window


to uninstall one virtual environment:
pyenv uninstall <virtual env name>

Open in new window


to list all python versions:
pyenv versions

Open in new window


to install a python version:
pyenv install <version number>

Open in new window


to set a folder to use a specific python version:
pyenv local <python version>

Open in new window



I think this got everything covered, right?
0
 

Author Comment

by:sharingsunshine
ID: 41760191
I uninstalled the 15.0.3 virtual environment

(test_env) rjw pip install selenium
Collecting selenium
  Using cached selenium-2.53.6-py2.py3-none-any.whl
Installing collected packages: selenium
Successfully installed selenium-2.53.6

Open in new window


My selenium is what I started with how do I get it to 3.0?

(test_env) rjw pip install selenium -U
Requirement already up-to-date: selenium in /Users/rjw/.pyenv/versions/3.3.6/envs/test_env/lib/python3.3/site-packages
(test_env) rjw idle
pyenv: idle: command not found

The `idle' command exists in these Python versions:
  2.6.9
  2.7.10
  3.2.6
  3.3.6
  3.4.3
  3.5.0

(test_env) rjw pyenv local 3.3.6
(test_env) rjw idle
pyenv: idle: command not found

Open in new window


the upgrade didn't work

how do I use idle like I did before and how do I run the python scripts?
0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41760216
Why do you want to upgrade? You just have installed the latest version.
About executing python script, just type on the terminal:
python <script name>

Open in new window


About idle, I dont have a clue on why it is not working... but you can use any other editor. Probably xcode will be the best.
0
 

Author Comment

by:sharingsunshine
ID: 41760227
I need 3.0 to be compliant with my FireFox.  Which is why I started this question since it will open a blanks FF window but doesn't have any url in it.

Traceback (most recent call last):
  File "expertsBrazil2webdriver.py", line 8, in <module>
    browser = webdriver.Firefox()
  File "/Users/rjw/.pyenv/versions/test_env/lib/python3.3/site-packages/selenium/webdriver/firefox/webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "/Users/rjw/.pyenv/versions/test_env/lib/python3.3/site-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/Users/rjw/.pyenv/versions/test_env/lib/python3.3/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/Users/rjw/.pyenv/versions/test_env/lib/python3.3/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 108, in _wait_until_connectable
    % (self.profile.path))
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /var/folders/vg/lzbgw_fx4k90zdjn3zy95qt80000gp/T/tmpf2k_ek If you specified a log_file in the FirefoxBinary constructor, check it for details.

Open in new window


Looking online it said selenium 3.0 would work with python 3.3.6
https://pypi.python.org/pypi/selenium
0
 

Author Comment

by:sharingsunshine
ID: 41760294
You have certainly answered the question just seems like there is some other dependency keeping me from having selenium 3.0.  However, I will revert back to my original question or post another one to get than answer.
0
 

Expert Comment

by:Naina Reddy
ID: 41875157
Hi,
Uninstall Python 3.5 by going to control panel, uninstall a program, and then look for Python 3.5, click on it and press uninstall. After that download Python 3.3. I don't know any other ways but I think that should work.
Regards,
Naina Reddy
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now