PROGRAMMING:

How to Set Up Virtual Environments Using Different Python Versions on Windows

Nice and easy tutorials with step-by-step instructions

David Littlefield
5 min readJul 31, 2020
Image by David Clode

Summary:

This article uses a simple technique to create virtual environments using different python versions. It installs every major version of python, adds each version to the path environment variable, and renames the executable files to include the version number. It also creates, activates, and operates a virtual environment using one of the renamed python executable files.

Table of Contents:

  1. Install the Different Python Versions
  2. Install the Requirements
  3. Create the Virtual Environment
  4. Check the Different Python Versions

Appendix:

  1. Tutorials: Artificial Intelligence Set Up
  2. Tutorials: Artificial Intelligence Course
  3. Tutorials: Artificial Intelligence Repositories

Install the Different Python Versions:

This section allows scripts to run in powershell, creates a python directory, opens the python directory, and backs up the path environment variable.

# open the powershell shell
1. press “⊞ windows”
2. enter “powershell” into the search bar
3. right-click "windows powershell"
4. click “run as administrator”
# allow scripts to run in powershell
set-executionpolicy unrestricted -force
# creates the python directory
mkdir -p "$home\appdata\local\programs\python"
# open the python directory
cd "$home\appdata\local\programs\python"
# backup the path environment variable
[system.environment]::getenvironmentvariable('path','user') > path-environment-variable-backup.txt

Install Python 3.5:

This section downloads and installs python 3.5, adds python 3.5 to the path environment variable, and renames the python 3.5 executable file.

# download python 3.5
invoke-webrequest -uri https://www.python.org/ftp/python/3.5.4/python-3.5.4-amd64.exe -outfile "$home/downloads/python-3.5.4.exe"
# install python 3.5
invoke-item "$home\downloads\python-3.5.4.exe"
# add python 3.5 to the path environment variable
$new_paths = "$home\appdata\local\programs\python\python35\scripts\;
$home\appdata\local\programs\python\python35\"; $old_paths = [system.environment]::getenvironmentvariable('path','user'); [environment]::setenvironmentvariable("path", "$new_paths; $old_paths", "user")
# rename the python 3.5 executable file:
copy python35\python.exe python35\python35.exe

Install Python 3.6:

This section does the same thing as the last section but with python 3.6.

# download python 3.6
invoke-webrequest -uri https://www.python.org/ftp/python/3.6.8/python-3.6.8-amd64.exe -outfile "$home/downloads/python-3.6.8.exe"
# install python 3.6
invoke-item "$home\downloads\python-3.6.8.exe"
# add python 3.6 to the path environment variable
$new_paths = "$home\appdata\local\programs\python\python36\scripts\;
$home\appdata\local\programs\python\python36\"; $old_paths = [system.environment]::getenvironmentvariable('path','user'); [environment]::setenvironmentvariable("path", "$new_paths; $old_paths", "user")
# rename the python 3.6 executable file:
copy python36\python.exe python36\python36.exe

Install Python 3.7:

This section does the same thing as the last section but with python 3.7.

# download python 3.7
invoke-webrequest -uri https://www.python.org/ftp/python/3.7.9/python-3.7.9-amd64.exe -outfile "$home/downloads/python-3.7.9.exe"
# install python 3.7
invoke-item "$home\downloads\python-3.7.9.exe"
# add python 3.7 to the path environment variable
$new_paths = "$home\appdata\local\programs\python\python37\scripts\;
$home\appdata\local\programs\python\python37\"; $old_paths = [system.environment]::getenvironmentvariable('path','user'); [environment]::setenvironmentvariable("path", "$new_paths; $old_paths", "user")
# rename the python 3.7 executable file:
copy python37\python.exe python37\python37.exe

Install Python 3.8:

This section does the same thing as the last section but with python 3.8.

# download python 3.8
invoke-webrequest -uri https://www.python.org/ftp/python/3.8.6/python-3.8.6-amd64.exe -outfile "$home/downloads/python-3.8.6.exe"
# install python 3.8
invoke-item "$home\downloads\python-3.8.6.exe"
# add python 3.8 to the path environment variable
$new_paths = "$home\appdata\local\programs\python\python38\scripts\;
$home\appdata\local\programs\python\python38\"; $old_paths = [system.environment]::getenvironmentvariable('path','user'); [environment]::setenvironmentvariable("path", "$new_paths; $old_paths", "user")
# rename the python 3.8 executable file:
copy python38\python.exe python38\python38.exe

Install Python 3.9:

This section does the same thing as the last section but with python 3.9.

# download python 3.9
invoke-webrequest -uri https://www.python.org/ftp/python/3.9.6/python-3.9.6-amd64.exe -outfile "$home/downloads/python-3.9.6.exe"
# install python 3.9
invoke-item "$home\downloads\python-3.9.6.exe"
# add python 3.9 to the path environment variable
$new_paths = "$home\appdata\local\programs\python\python39\scripts\;
$home\appdata\local\programs\python\python39\"; $old_paths = [system.environment]::getenvironmentvariable('path','user'); [environment]::setenvironmentvariable("path", "$new_paths; $old_paths", "user")
# rename the python 3.9 executable file:
copy python39\python.exe python39\python39.exe

Install the Requirements:

This section reloads the path environment variable, installs the virtualenv library on each python version, and opens the desktop directory.

# reload the environment variables
$env:path = [system.environment]::getenvironmentvariable("path","machine") + ";" + [system.environment]::getenvironmentvariable("path","user")
# install virtualenv on python 3.5
python35 -m pip install virtualenv
# install virtualenv on python 3.6
python36 -m pip install virtualenv
# install virtualenv on python 3.7
python37 -m pip install virtualenv
# install virtualenv on python 3.8
python38 -m pip install virtualenv
# install virtualenv on python 3.9
python39 -m pip install virtualenv
# navigate to the desktop directory
cd $home\desktop

Create the Virtual Environment:

This section creates, activates, and operates the virtual environment.

# create the python 3.5 virtual environment
python35 -m virtualenv venv35
# activate the python 3.5 virtual environment
venv35\scripts\activate
# check the python version
python --version
# check the location of the python executable file
(get-command python).path
# install a package using the pip package manager
python -m pip install numpy
# list all the packages that are currently installed
python -m pip list
# uninstall a package using the pip package manager
python -m pip uninstall --yes scipy
# list all the packages that are currently installed
python -m pip list
# deactivate the python 3.5 virtual environment
deactivate

Check the Different Python Versions:

This section checks the version of each python version that’s installed.

# print the different versions of python
echo "$(python35 --version; python36 --version; python37 --version; python38 --version; python39 --version)"

“Lastly, remember to hold down the clap button and subscribe to help out and get regular updates.”

Appendix:

This blog exists to provide complete solutions, answer your questions, and accelerate your progress related to artificial intelligence. It has everything you need to set up your computer and complete the first half of the fastai course. It will expose you to state-of-the-art repositories in the subfields of artificial intelligence. It will also cover the second half of the fastai course.

Tutorials: Artificial Intelligence Set Up

This section provides everything that’s required to set up your computer.

# linux
01. install and manage multiple python versions
02. install the nvidia cuda driver, toolkit, cudnn, and tensorrt
03. install the jupyter notebook server
04. install virtual environments in jupyter notebook
05. install the python environment for ai and machine learning
06. install the fastai course requirements
# wsl 2
01. install windows subsystem for linux 2
02. install and manage multiple python versions
03. install the nvidia cuda driver, toolkit, cudnn, and tensorrt
04. install the jupyter notebook server
05. install virtual environments in jupyter notebook
06. install the python environment for ai and machine learning
07. install ubuntu desktop with a graphical user interface
08. install the fastai course requirements
# windows 10
01. install and manage multiple python versions
02. install the nvidia cuda driver, toolkit, cudnn, and tensorrt
03. install the jupyter notebook server
04. install virtual environments in jupyter notebook
05. install the python environment for ai and machine learning
06. install the fastai course requirements
# mac
01. install and manage multiple python versions
02. install the jupyter notebook server
03. install virtual environments in jupyter notebook
04. install the python environment for ai and machine learning
05. install the fastai course requirements

Tutorials: Artificial Intelligence Course

This section contains answers to the questionnaire at the end of each lesson.

# fastai
01. chapter 1: your deep learning journey q&a
02. chapter 2: from model to production q&a
03. chapter 3: data ethics q&a
04. chapter 4: under the hood: training a digit classifier q&a
05. chapter 5: image classification q&a
06. chapter 6: other computer vision problems q&a
07. chapter 7: training a state-of-the-art model q&a
08. chapter 8: collaborative filtering deep dive q&a

Tutorials: Artificial Intelligence Repositories

This section contains state-of-the-art repositories in the different subfields.

# repositories related to audio
01. raise audio quality using nu-wave
02. change voices using maskcyclegan-vc
03. clone voices using real-time-voice-cloning toolbox
# repositories related to images
01. achieve 90% accuracy using facedetection-dsfd

--

--

David Littlefield
David Littlefield

Written by David Littlefield

From: Non-Technical | To: Technical Founder | Writes: To Make It Easier For Everyone | Topics: #Startups #How-To #Coding #AI #Machine Learning #Deep Learning

Responses (2)