How to install wxPython in a Python virtual environment on Debian Buster

wxPython logoLately, I’ve been brushing up on my Python skills, and decided to use wxPython for some GUI programming.  But, I had some trouble installing wxPython in a Python virtual environment on Debian, so once I figured it out, I’ve recorded what I had to do in case anyone else needs to do the same thing.

Note that if you’re NOT using a virtual environment, it’s pretty easy: just install the “python3-wxgtk4.0” package.  Of course, if you’re using Python 2, you’ll need something else, but because Python 2 has reached end-of-life, I don’t know why you’d want to use that!  Anyways, just as a refresher, to install a Debian package, you’ll need to run the following from the command line as root:

apt-get install python3-wxgtk4.0

You may, of course, need to run it with sudo to run as root:

sudo apt-get install python3-wxgtk4.0

In this post, rather than saying whether to run something as root or as a regular user, I’m just going to prepend the root commands with “sudo”; if you get root access another way, do that instead.

OK, but as I said, I want to install wxPython in a Python virtual environment.  The problem comes because Python needs to compile wxPython, so you need a number of development packages installed.  You actually need hundreds of packages (!), but I’ve narrowed it down to a short list, and the other packages will be installed as dependencies of these ones.

Note that I am currently running Debian Buster.  I’ve tried this out with a basic non-GUI install of Buster, as well as with the XFCE desktop installed (which I set up via “sudo tasksel install xfce-desktop”).

First thing you need to do if you’re going to use Python virtual environments on Debian is to install the Python virtual environment package:

sudo apt-get install python3-venv

Now, you can create your Python virtual environment:

python3 -m venv example-env

This will create your Python virtual environment in a directory called example-env.

Now, install all of required Debian development packages:

sudo apt-get install build-essential python3-dev \
  libwebkit2gtk-4.0-dev libtiff-dev libnotify-dev \
  freeglut3-dev libsdl1.2-dev libgstreamer-plugins-base1.0-dev

This will cause hundreds of packages to be installed, so don’t be surprised when that happens!

Once you’ve got those installed, you’re almost all set.  Activate your Python virtual environment:

source example-env/bin/activate

Using Python’s “pip” program, install the “wheel” Python package into the virtual environment:

pip install wheel

And now, finally, you can install wxPython:

pip install wxPython

Be aware that this is going to result in the wxPython package being compiled, which can take a LONG time.  Don’t be surprised if it takes an hour or more.  But, once it’s successfully installed, you can use wxPython in your virtual environment!  I tested it out by running the helloworld2.py program found on the wxPython Overview page.

Have fun!

Installing Anaconda on Debian

Screenshot of Anaconda logoIn this post, I present step-by-step instructions for installing Anaconda, a Python package manager for data science, and a number of included data science Python packages, including Spyder and Jupyter Notebook.

What is Anaconda?

If you want to do some data science with Python, it is highly recommended that you use Anaconda.  According to the Anaconda website, “Anaconda® is a package manager, an environment manager, a Python/R data science distribution, and a collection of over 1,500+ open source packages.”  So, what that means is that it looks after installing and managing various Python packages for data science in an easy-to-use manner. It’s way easier than dealing with all the interactions and dependencies between the various versions of those packages.

Why do you want to use Anaconda?  Again, according to the Anaconda Starter Guide:

Many scientific packages require a specific version of Python to run. It’s difficult to keep various Python installations on one computer from interacting and breaking, and harder to keep them up-to-date. Anaconda Distribution makes management of multiple Python versions on one computer easier, and provides a large collection of highly optimized, commonly used data science libraries to get you started faster.

What is included with Anaconda?  From that Starter Guide, here’s the highlight of some of the things that are either installed with Anaconda, or can be installed with Anaconda:

  • NumPy: scientific computer library for Python
  • SciPy: scientific computing library for Python
  • Matplotlib:2D plotting library for Python
  • Pandas: powerful Python data structures and data analysis toolkit
  • Seaborn: statistical graphics library for Python
  • Bokeh: interactive web visualization library
  • Scikit-Learn: Python modules for machine learning and data mining
  • NLTK: natural language toolkit
  • Jupyter Notebook: web app that allows you to create and share documents that contain live code, equations, visualizations and explanatory text
  • R essentials: 80+ of the most used R packages for data science

That’s just a few of the highlights. There are over 1500 packages that can be installed with Anaconda.

This post leads you through the steps to install Anaconda on a computer running the Debian Linux distribution.  My Debian box (actually, a Vagrant Virtualbox VM running Debian) uses the XFCE desktop environment; you’ll need some GUI to use Anaconda.  But, you can also use the command-line based “conda” program if you don’t want a GUI.

Installing Anaconda

The Anaconda website is at https://www.anaconda.com.  The documentation for it is at https://docs.anaconda.com/anaconda/. You can find the downloads at https://www.anaconda.com/distribution/; at the time of this writing, the latest version for Linux is Anaconda 2018.12.  I’m going to use the Python 3.7 version; if you want to use the Python 2.7 version, download that instead.  You can see all the downloads at https://repo.anaconda.com/archive/.  Either download the installer with your browser, or download it from a Terminal window.  I downloaded it from a Terminal window.

Open a Terminal window on the GUI, and download the latest 64-bit version of the Anaconda installer:

wget https://repo.anaconda.com/archive/Anaconda3-2018.12-Linux-x86_64.sh

 

Download the Anaconda installer

It’s quite large (652.5M), so it takes a while to download.

Installation instuctions are at https://docs.anaconda.com/anaconda/install/linux/.  To install:

bash Anaconda3-2018.12-Linux-x86_64.sh

Be sure you execute this in the directory that you downloaded the file to!

Executing the Anaconda installer

  • Press enter to review the license agreement, hitting space to scroll through the agreement.  When asked if you accept the license terms, type yes and press enter to accept.

Accept license terms

  • Press enter to confirm the install location of /home/username/anaconda3 (for me, my username is vagrant)

Specify installation directory

  • The installer now installs a number of packages, and then asks if you want the installer to initialize Anaconda in your .bashrc file

Confirm changes to bashrc

  • Typically, you’ll want the installer to update your .bashrc file.  Type yes and press enter to do so. You might not want it to if you have multiple installations of Anaconda, but that’s pretty rare.
  • After your .bashrc file is updated, you’ll be asked if you want to install Microsoft VSCode.

VSCode installation prompt

  • I’m not going to install it.  Type no and press enter to NOT install Microsoft VSCode.  Note: if you want to install it, you would need to run the installer as root.

Don't install VSCode

  • Close and re-open the Terminal window so that the changes to your .bashrc file are read in.

You can check for successful installation by running “anaconda-navigator” from the terminal.

anaconda-navigator

When it starts up, you’ll be asked if you want to provide anonymized usage information.  If you’re OK with that, click the “OK, and don’t show again” button (otherwise, it asks every time you start it up); if not, uncheck the “Yes, I’d like to help improve Anaconda.” checkbox, then click the “OK, and don’t show again” button.

Anaconda Navigator usage info request

And here’s Anaconda Navigator in all its glory!

Anaconda Navigator screenshot

Notice the applications that have been installed.  I’ve got:

  • Jupyter Lab 0.35.3
  • Jupyter Notebook 5.7.4
  • Jupyter Qt console 4.4.3
  • Spyder 3.3.2

Exit anaconda-navigator (File / Quit).  If told that Anaconda Navigator is still busy, click Yes to exit.

The installer and the packages that it includes are quite large.  Let’s free up some space now. First, delete the file Anaconda3-2018.12-Linux-x86_64.sh.

rm Anaconda3-2018.12-Linux-x86_64.sh

Then, using conda, the command line version of Anaconda, remove the downloaded package installers.  From the Terminal, run:

conda clean --tarballs

You’ll be given a list of all of the package installers that will be deleted, as well as the size of those files.  You’ll then be asked whether to proceed; type y and press enter to delete them.

Updating packages installed with Anaconda

Now, let’s make sure we’ve got all of the latest versions of packages that have been installed with Anaconda.  But, rather than using Anaconda, we’ll use the command line version, conda. The reason for this is you need to update packages one at a time with Anaconda; with conda, you can update everything at once.

In your Terminal window, execute:

conda update --all

This will check to see which packages can be updated, list them, and ask you to proceed.  Type y and press enter.

After doing this, free up space again:

conda clean --tarballs

And, you’ve now got Anaconda installed and up-to-date!