Professional Documents
Culture Documents
How To Set Up Virtual Environment For Jupyter Notebook
How To Set Up Virtual Environment For Jupyter Notebook
Notebook
As a data scientist you may want to enjoy the benefit of setting up more than one virtual
environment for your work. Some of the reasons why we may want more than one
environment may be.
1. To control the version of libraries installed in each environment for a specific work
2. Separating aa development environment from a test environment
3. Experiment with some packages without messing up your main installations.
Key Steps
Open a terminal
Setup the pip package manager
Install the virtualenv package
Create the virtual environment
Activate the virtual environment
Deactivate the virtual environment
Requirements
1. Install python package from https://www.python.org/downloads/
2. During installation of python, ensure you select the option to
add it to your PATH variable
install for everyone (you can also choose the alternative to install just for
yourself)
3. Check that Python is properly installed
Open CMD in windows or Terminal in Mac and run the following code:
i. Python --version
4. Upgrade PIP: Type the following in the CMD window and click enter
Notes:
If you downloaded and installed python from python.org and accepted all the defaults during installation,
python.exe may be found in one of the following locations:
64-bit (Preferred):
C:\Users\%username%\AppData\Local\Programs\Python\Python36\python.exe
32-bit:
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
CREATING A VIRTUAL ENVIRONMENT
A virtual environment is installed in a specific location. If you do not specify the location, it will
be installed in the current local folder. SO follow these steps to create your virtual
environment:
1. Create the Folder where the virtual environment will be located
a. Go to the DOCUMENTS folder in your computer
b. Create a new folder there and name it Workspace
c. Right-click the new workspace folder and click on the PROPERTIES link
d. Copy/Note the path to the folder
2. Launch CMD or Terminal window
1. On Windows, click on the search window on your task bar and type CMD. If this
does not work, simply click on Run to launch CMD
2. On Mac, Launch Terminal
3. On the open CMD/Terminal window, navigate to the WORKSPACE folder you created
a. The current path in the CMD window should be something like:
C:\windows\system32
4. Install virtualenv. The virtualenv package is required to create virtual environments.
You can install it with pip.
a. Type the following in the CMD window and click the ENTER key to Run
pip install virtualenv
5. Create the virtual environment
To create a virtual environment, you must specify a name for the virtual environment
complete with the path to the folder where it should be created. We will use the Path to
the Workspace folder we created earlier.
Since we already created a folder, we need to change the directory in CMD and navigate
into the workspace folder to install the virtual environment.
Change directory in the CMD window until you are in the Workspace folder.
Steps:
On the open CMD/Terminal window, navigate to the WORKSPACE folder you created
1. The current path in the CMD window should be something like:
C:\windows\system32
2. Use cd.. to back out of the system folder and repeat until you are in the C:\
drive
Type cd.. and hit the ENTER key. Repeat this step until all you have on the
CMD line is C:\>
3. Next; Use cd users\USERNAME\Documents\Workspace to change to the
workspace folder
Type cd users and hit the ENTER key: This navigates into the USERS
Directory.
1. Your CMD line at this point should be:
C:\users
Type cd USERNAME and hit the ENTER key. This navigates into the
current logged in user Directory.
1. (Please replace USERNAME with the one in your directory path.
note that USERNAME is usually the current logged in account on
your computer, so it is going to be different)
2. Your CMD line at this point should be:
C:\users\USERNAME
Type cd documents and hit the ENTER key. This navigates into the
DOCUMENTS Directory.
1. Your CMD line at this point should be:
C:\users\USERNAME\documents
Type cd workspace and hit the ENTER key. This navigates into the
WORKSPACE Directory.
1. Your CMD line at this point should be:
C:\users\USERNAME\documents\workspace
You can activate the python environment by running the following command:
a. On a Mac OS / Linux
source onecampusenv /bin/activate
b. On a Windows PC
onecampusenv \Scripts\activate
c. You should see the name of your virtual environment in brackets on your
terminal line e.g. (onecampusenv).
d. Any python commands you use will now work with your virtual environment
3. Done. You may now use Jupyter notebook under the virtual environment.
jupyter-notebook
This will either launch a web browser with Jupyter Notebook running in it
If the web browser does not automatically open, you can launch it by copying the URL
from the CMD window and then run that on a web browser
10. To Close Jupyter Notebook When you are done with your work
When you are done with your Jupyter notebook, you can close the virtual environment
using the following steps:
1. Save your jupyter notebook by clicking FILE RENAME
2. Save your jupyter notebook by clicking on the SAVE menu
3. Click on the QUIT menu item
4. Go to the CMD window and type the following
deactivate
That’s it!
STEPS TO RESTART YOUR VIRTUAL ENVIRONMENT ANYTIME
11. Launch CMD or Terminal window
3. On Windows, click on the search window on your task bar and type CMD. If this
does not work, simply click on Run to launch CMD
4. On Mac, Launch Terminal
12. On the open CMD/Terminal window, navigate to the WORKSPACE folder you created
a. The current path in the CMD window should be something like:
C:\windows\system32
b. Use cd.. to back out of the system folder and repeat until you are in the C:\
drive
i. Type cd.. and hit the ENTER key. Repeat this step until all you have on the
CMD line is C:\>
c. Next; Use cd users\USERNAME\Documents\Workspace to change to the
workspace folder
i. Type cd users and hit the ENTER key: This navigates into the USERS
Directory.
1. Your CMD line at this point should be:
C:\users
ii. Type cd USERNAME and hit the ENTER key. This navigates into the
current logged in user Directory.
1. (Please replace USERNAME with the one in your directory path.
note that USERNAME is usually the current logged in account on
your computer, so it is going to be different)
2. Your CMD line at this point should be:
C:\users\USERNAME
iii. Type cd documents and hit the ENTER key. This navigates into the
DOCUMENTS Directory.
1. Your CMD line at this point should be:
C:\users\USERNAME\documents
iv. Type cd workspace and hit the ENTER key. This navigates into the
WORKSPACE Directory.
1. Your CMD line at this point should be:
C:\users\USERNAME\documents\workspace
c. You should see the name of your virtual environment in brackets on your
terminal line e.g. (onecampusenv).
14. Start Jupyter Notebook
jupyter-notebook