Create Virtual Environment, Install & Load Packages, Code within Jupyter Notebook or Spyder

To install Anaconda packages you must create a new virtual environment pointing to your U: drive. Information about the U: drive for your CISER account can be found inside the link below.
CISER Workspace

Confirmed process working on RSCH105.ciserrsch.cornell.edu

GREEN TEXT INDICATES A COMMENT. DO NOT ENTER GREEN TEXT INTO YOUR ANACONDA PROMPT. Regular colored text use as reference to enter into anaconda prompt
CONNECT TO CISER SERVERS. OPEN “ANACONDA PROMPT” FROM START MENU
Do work within U: drive
U:
Set directory using “cd” command. Directory is folder on U: drive where my work is. In example below
cd Documents
Create new folder inside Documents.
mkdir "conda_dir"
cd "conda_dir"

Create virtual environment. Will be created where directory was set to above. A folder “myenv” from code below will be created within “U:\Documents\conda_dir”
conda create --prefix ./myenv python=3.7
y

Activate newly created virtual environment below
activate "U:\Documents\conda_dir\myenv"
y

Install packages ‘gensim’ and ‘tensorflow’ as example. Use pip command to install
pip install gensim
pip install tensorflow

Incorporating Jupyter Notebook

For this demo I will initiate jupyter notebook and use a package with sample code.
Begin by following instructions above to create virtual environment. Install your desired package prior to starting jupyter notebook.
Use pip command to install libraries to your virtual environment
pip install keras
pip install tensorflow

Must install “jupyter” library to initiate from Anaconda command prompt
pip install jupyter
Will use “random2” package for my sample code
pip install random2
Initiate jupyter notebook with command below
jupyter notebook
You may have .ipynb files scattered all over your filing system. You can initiate your environment from any folder so long as you specify the location
jupyter notebook --notebook-dir U:/Documents
Command above opens Jupyter with Documents as home directory. Now I can access any .ipynb files inside all folders within Documents. This can be done with Desktop, Downloads, ect.
Some information gotten from following link.
pythonforundergradengineers.com

Sample Program

Once jupyter notebook has opened within a web browser use the program below to test. This program is dependent on the library “random2”, install in commands above.


#!/usr/bin/env python
import random # Get a random number generator.
NTRIALS = 10000 # Enough trials to get an reasonably accurate answer.
NPEOPLE = 30 # How many people in the group?
matches = 0 # Keep track of how many trials have matching birthdays.
for trial in range(NTRIALS): 12# Do a bunch of trials...
taken = {} # A place to keep track of which birthdays
# are already taken on this trial.
for person in range(NPEOPLE): 60# Put the people’s birthdays down, one at a time...
day = random.randint(0, 365) # On a randomly chosen day.
if day in taken:4
matches += 1 # A match! # No need to look for more than one.
taken[day] = 1 # Mark the day as taken.
print("The fraction of trials that have matching birthdays is", float(matches)/NTRIALS)

Using Spyder

Open Anaconda prompt.
Activate directory using steps at beginning of article.


pip install spyder
Use pip command to install other libraries to your virtual environment
pip install random2
Initiate Spyder application with command below
spyder

Run test program dependent on random2 library.

#!/usr/bin/env python
import random # Get a random number generator.
NTRIALS = 10000 # Enough trials to get an reasonably accurate answer.
NPEOPLE = 30 # How many people in the group?
matches = 0 # Keep track of how many trials have matching birthdays.
for trial in range(NTRIALS): 12# Do a bunch of trials...
taken = {} # A place to keep track of which birthdays
# are already taken on this trial.
for person in range(NPEOPLE): 60# Put the people’s birthdays down, one at a time...
day = random.randint(0, 365) # On a randomly chosen day.
if day in taken:4
matches += 1 # A match! # No need to look for more than one.
taken[day] = 1 # Mark the day as taken.
print("The fraction of trials that have matching birthdays is", float(matches)/NTRIALS)