Step-by-step guide for solving the Pyvttbl Float and NoneType error

In this short post, I will show you a quick fix for the error “unsupported operand type(s) for +: ‘float’ and ‘NoneType’” with Pyvttbl. In earlier posts, I have shown how to carry out ANOVA using Pyvttbl (among other packages. See posts 1, 2, 3, and 4 for ANOVA using pyvttbl).

However,  Pyvttbl is not compatible with Python versions greater 1.11 (e.g., 1.12.0, that I am running). This may, of course, be due to that Pyvttbl have not been updated in quite some time.

My solution to this problem involves setting up a Python virtual environment (the set up of the virtual environment it is based on the Hitchikers Guide to Python). You will learn how to set up the virtual environment in Linux and Windows.

Table of Contents

How to Solve Pyvttbl Float and NoneType Error in Linux

In this section, you will learn 3 steps to solve the “Float and NoneType Error” when trying to run pyvttbl in e.g. Ubuntu Linux.

Step 1: Install Virtualenv & Create a Virtual Environment

First, we will need to install the package virtualenv:

pip install virtualenvCode language: Bash (bash)

Next, we continue with opening up a terminal window. Here, we change the directory to the where we typically have our Python projects and create a directory for our new Pyvttbl environment:

How to set up virtual environment - tarting by creating it
  • Save

Step 2: Activate the Virtual Environment

The next step is to activate the virtual environment:

source pyvttbl_env/bin/activateCode language: Bash (bash)

Step 3: Use Pip to Install a Specific Version of NumPy

Now we should have a virtual environment set up and we can start installing numpy 1.1.0 and pyvttbl:

pip install numpy==1.11.0 pyvttblCode language: Bash (bash)

In the code snippet above, it is important that you set the version of Numpy (e.g., 1.11.0) that we want to install. Thus, we get the version that has been previously working with Pyvttbl.

  • Save

Remember, if we want to use any other Python packages (e.g., jupyter notebooks, Seaborn, matplotlib) we need to install them in our virtual environment. We can, of course, just add any package to the pip install snippet above:

pip install numpy==1.11.0 pyvttbl jupyter matplotlib seabornCode language: Bash (bash)

Note it is simple to use Pip to install a specific version of a Python package as well as setting versions on many packages. Now, let’s check the version of Numpy using iPython:

  • Save

Finally, if we want to do our ANOVA in a jupyter notebook we need to install a new kernel that uses the one in the virtual environment.

If we don’t do this we will run the notebook from the global environment and, thus, we will import whatever version of Numpy we have installed on the system:

ipython kernel install --name "pyvttbl_env" --userCode language: Bash (bash)
  • Save

If we follow the image above, we also start up a Jupyter notebook. When creating a new notebook to run our python ANOVAs using pyvttbl in we need to select our new core (i.e., pyvttbl_env”).

In the notebook below (after Windows set-up) you can see that we don’t get the error “unsupported operand type(s) for +: ‘float’ and ‘NoneType’”. Note, we do get a warning that in the future what pvttbl is trying to do is not going to work.

3 Steps to Solve the Pyvttbl Problem on Widows

For Windows, the set-up is basically the same.

Step 1: Install and Create a Virtual Env

First, we will need to install virtualenv:

pip install virtualenvCode language: Bash (bash)

The next step for Windows users is, of course, similar but we need to start the Command Prompt (here is how). Let’s change the directory to where our Python projects are intended to be stored and create the new Pyvttbl environment.

First, we create a directory and then we create the virtual environment in this directory:

  • Save

Step 2: Activating the Virtual Env

We continue by activating our virtual environment for running Numpy 1.11.0 and Pyvttbl:

  • Save

The next step is to activate our virtual environment. Here, it is a bit different for Windows users compared to Linux users:

source pyvttbl_env/Scripts/activateCode language: Bash (bash)

Step 3: Install an Older Version of NumPy

Now that we have a virtual environment set up we can install an older version of Numpy. Here we will also depart on how this is done in Linux.

I had a bit of a problem with installing Scipy (Pyvttbl depends on Scipy, for instance) using Pip.

Fortunately, there are Windows binaries for both Numpy and Scipy. Download the version you need and put it in the directory for the virtual environment and use pip to install:

pip install numpy-1.11.3+mkl-cp27-cp27m-win32.whl scipy-0-19.1-cp27-cp27m-win32.whlCode language: Bash (bash)

Any additional packages that we may need in our data analysis will, of course, also have to be installed in the virtual environment. Luckily us, we can just use pip again (no external downloading, that is!):

pip install jupyter matplotlib seabornCode language: Bash (bash)

Since we plan to run our ANOVA in a notebook we have one final step that needs to be done. To get Jupyter to run WITHIN the virtual environment (or else it will use whatever Numpy version we had problems with earlier). Thus, we need to install a new kernel for the virtual environment. This is easily done using the command prompt, again:

ipython kernel install --name "pyvttbl_env" --userCode language: Bash (bash)
  • Save

Jupyter notebook

In this notebook, we can run our ANOVA using pyvttbl without the “unsupported operand type(s) for +: ‘float’ and ‘NoneType’ error!

Note, Windows users will have a different Numpy version (we installed 1.11.3) and if you run Linux you can, of course, install this version too. Of course, we do get the warning (the future is now!)

That was it, now we can use Pyvttbl on both Linux and Windows computers without the problem with float/NoneType. This is of course not an optimal solution but it does the trick. If anyone have other ideas on how to solve this problem, please let me know.

  • Save

7 thoughts on “Step-by-step guide for solving the Pyvttbl Float and NoneType error”

      1. Hi Erik,
        I am looking forward to your new post about how to conduct a repeated measure ANOVA with statsmodels! And I also wonder how to calculate η^2 and relevant correction for sphericity. Thank you for your effort!

      2. Hi Erik, this sounds great! The RM-ANOVA support is currently only included in the master branch, as far as I know, and it only supports within-subject designs. But things are slowly (but steadily) improving 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top
Share via
Copy link
Powered by Social Snap