When you start working with Python it is great practice to create isolated Python environments to work on your specific projects.
The standard python environment is used by a large number of system scripts and therefore best to leave alone. In addition, when working on different projects, those projects may have different and conflicting dependencies and therefore should ideally be installed in their own python environments. The ability to create different python environments can also be really beneficial when developing your own python packages and thereby test its installation and performance in different versions of python.
Below I guide you through the basic steps of installing and working with python virtual environments.
Installing OpenCV has never been easy and always required a lot of careful usage of the command line to build from source. This was especially painful when working with a Raspberry Pi as building and installing OpenCV took a lot of time on the RPi, especially on the older models. Luckily this has changed very recently as it is now possible to install OpenCV with pip!
Below I guide you through the basic steps that I think are necessary to get opencv to work nicely on Mac, Ubuntu and Raspberry Pi. If you want more background information, see the excellent article by Adrian Rosebrock from PyImageSearch.com.
FFmpeg is a great little program to help convert more or less any media format. I previously wrote an article how to install ffmpeg on the Raspberry Pi. This short tutorial will help you install ffmpeg on Mac, which is luckily a lot simpler!
The easiest way to install ffmpeg is to use HomeBrew a package manager for Mac. If you don’t have homebrew installed on your mac already, run the following command using terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Once you have Homebrew installed, you can now simply install ffmpeg from terminal with the following command:
brew install ffmpeg
To install ffmpeg with specifical modules, instead of running the above command run below command or remove those modules you do not need:
brew install ffmpeg --with-chromaprint --with-fdk-aac --with-fontconfig --with-freetype --with-frei0r --with-game-music-emu --with-libass --with-libbluray --with-libbs2b --with-libcaca --with-libgsm --with-libmodplug --with-librsvg --with-libsoxr --with-libssh --with-libvidstab --with-libvorbis --with-libvpx --with-opencore-amr --with-openh264 --with-openjpeg --with-openssl --with-opus --with-rtmpdump --with-rubberband --with-sdl2 --with-snappy --with-speex --with-tesseract --with-theora --with-tools --with-two-lame --with-wavpack --with-webp --with-x265 --with-xz --with-zeromq --with-zim
To save a jupyter script as an executable .py script you can use the
nbconvert command in terminal:
$ jupyter nbconvert --to script [NOTEBOOK_NAME].ipynb
Make sure to either
cd into the directory where the ipynb file is located or to paste the complete path of the file. But even better is to call the command directly in a jupyter notebook by prepending
!, which will run bash code inside any jupyter script:
!jupyter nbconvert --to script [NOTEBOOK_NAME].ipynb
In this way you can save your .ipynb file to .py file in an easy and fast way and only when you need it, such as when pushing a commit to github, saving time compared to when using auto convert.
The last few weeks I delved into learning , a code language for more aesthetically pleasing article writing, especially in terms of mathematical formulas. As my research has increasingly been focused on the mechanisms underlying collective behaviour, for which I do a lot of mathematical computations, such an advanced yet simple text-editor is very helpful and overcomes the many pains I have with MS word!
It was quite a steep learning curve, but I managed to write my first paper with it last week. The great thing is that it is also possible to use in wordpress (which I used to create this website). It is also the standard language for drafting preprint articles, which is increasingly suggested and done in the biological sciences, thus a very relevant skill to learn.
In my previous post I showed a fully interactive online graph of one of the plots in my recent paper on leadership in sticklebacks. In this follow-up post I will explain how to easily create such an interactive plot yourself. To be able to do this you will need some experience with the R-language and ideally with ggplot2.
First create an account at plot.ly, which is free. After you have created your account, go to “settings” and click on “generate API key”. You will need your username and this key to link your account to R.
Now you have your account ready start-up R and set-up the R workspace:
# Install the necessary packages
# Now load the packages
# Set your Plotly user credentials