Surviving without Anaconda
What’s a coder to do when Anaconda is taken away?
Do I really need virtual environments?
Need a refresher on virtual environments? Hop back and read about virtualenv.
You don’t necessarily need to use them, no.
While there are a lot of benefits once things start getting crazy, the simplest reason is this: if you use virtual environments, typing python
will always call the ‘right’ one.
Once I run workon marksclass
, my python
and pip
will always be Python 2. If I do workon data
my python
will always be Python 3, and same for pip
. As long as I set the environments up right, of course!
If you want to try to not use virtual environments, you can always try to use python
and python3
instead. I find that I forget to type the 3
sometimes, though, and print statements and the like suddenly look very silly.
Get into a virtual environment
workon dataclass
Exit a virtual environment
deactivate
Create a virtual environment
# Python 3 (default)
mkvirtualenv python3class
# Python 2
mkvirtualenv -p python2.7 python2class
You can call them whatever you’d like, of course.
Jupyter Notebooks
Now that we’ve gone and uninstalled Anaconda, trying to run jupyter notebook
doesn’t work any more!
You can install it using the Python package manager pip
:
pip install jupyter
Things can get tricky with virtual environments and Jupyter Notebooks. It’s probably best to install it once in your Python 2, then again in your Python 3 environment.
Once you’ve used pip
to install it, you can run your notebooks with the regular jupyter notebook
command.
Fixing missing modules
Since Anaconda auto-installs a lot of packages for you, at some point you’ll probably also run into an error that looks like this.
ImportError: No module named 'XXXXX'
Maybe the requests
module, for example. Each time you run into one of those issues, you’ll need to run pip install [modulename]
.
So if it’s complaining about requests
not existing, I would use the following to install it.
pip install requests
You’ll need to do this less and less as time goes on.
Installing R and Jupyter (OS X)
If you don’t need R, ignore this part.
To check if R is installed, open up Terminal, type r
and hit enter. If you get command not found
, you need to install it.
If you don’t already have R installed, we’re going to install it using Homebrew, an easy way to install and uninstall command-line utilities.
Note: Type these one at a time! In between some of the commands it might ask you for your password, and hitting enter will cause trouble.
brew install cask
brew cask install xquartz
brew tap homebrew/science
brew install r
If that doesn’t work, read through this SO q&a.
Now we’ll connect R and Jupyter.
Open Terminal, type r
and hit enter to go into the R console. Then paste in the following commands one at a time. The first one will prompt you to select a mirror to use, 1
is fine.
install.packages(c('openssl'))
install.packages(c('httr'))
install.packages(c('devtools'))
install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'uuid', 'digest'))
devtools::install_github('IRkernel/IRkernel')
IRkernel::installspec()
Exit with Ctrl+D
.
If these instructions do not work talk to me on Slack. The error messages are far worse than Python, and I had to tweak some things on my own installation (but I don’t know whether that’s universal or not).
Directions stolen from here
Now run jupyter notebook
and see if R is one of your kernel options! It should work no matter if you’re inside of or outside of a virtual environment.