Installation

Brightway2 can be installed pretty much everywhere, on Windows, OS X, Linux, and anywhere else Python can be compiled.

Note

Brightway2 supports python 2 and 3, but the recommended version is python 3.4.

Note

Please subscribe to the brightway2 updates mailing list to be informed of new releases.

Windows

Installation package

  1. Download the Brightway2 Windows installation package, and extract to the C:\ drive, using something like 7-zip. This will create the directory C:\bw2-python\. If you didn’t extract it to the right place, you can always move it afterwards.

Note

It is important that the final directory is exactly C:\bw2-python\, as this is what the batch files expect. If you want something more customized, please see the Advanced Installation instructions.

  1. As Brightway2 is in active development, make sure you have the latest sources by running (double-click) C:\bw2-python\bw2-update.bat.
  2. Launch (double-click) the application C:\bw2-python\bw2-notebook.bat to start a notebook server, or C:\bw2-python\bw2-ipython.bat to get an IPython shell.

You can safely move these batch files to your desktop for easy access.

Will the installation package mess up other installations of Python?

No, the installation package is completely independent, and doesn’t write anything into your system registry or any other global files.

Launching and using a command shell

You can also manually launch Python in a command shell using the application launcher. The launch procedure varies depending on the version of Windows you are running, but is usually next to the main Windows home button. Typing cmd should be enough to find the program you are looking for:

_images/cmd-shell-1.png

Note

You can usually use the right mouse button to paste into command shell or PowerShell windows.

You can copy and paste, or simply type commands, into the command shell. You will need to run the batch file C:\bw2-python\bw2-env.bat in each new command shell, to activate the brightway2 environment.

_images/cmd-shell-2.png

In the command shell, you can enter the ipython interpreter with ipython, or run notebooks with jupyter notebook. Note that you can’t launch the notebook server from the root C:\ drive, you must be in a directory, e.g. C:\bw2-python\.

Using PowerShell

PowerShell is more familiar for some people; in this case, you don’t want to run the batch file, but just directly add the relevant directories to your path:

$Env:Path = "c:\bw2-python\envs\bw2\Scripts\;C:\bw2-python\Scripts\;C:\bw2-python\;" + $Env:Path

You will have to do this in each PowerShell session.

PowerShell scripts are more powerful than normal batch scripts, but have more security features which have defeated my efforts to set the correct path programmatically. You are welcome to fix this!

Creating the installation package

The installation directory is created by following the advanced installation instructions, adding several batch files, and compressing the python directory.

bw2-env.bat

@ECHO OFF
ECHO Setting path to Brightway2 environment
set PATH=C:\bw2-python\envs\bw2\Scripts\;C:\bw2-python\Scripts\;C:\bw2-python\;%PATH%
CALL C:\bw2-python\Scripts\activate.bat bw2

bw2-update.bat

@ECHO OFF
set PATH=C:\bw2-python\envs\bw2\Scripts\;C:\bw2-python\Scripts\;C:\bw2-python\;%PATH%
CALL C:\bw2-python\Scripts\activate.bat bw2
@ECHO ON
pip install -U --no-deps --pre brightway2 bw2io bw2data bw2calc bw2analyzer
PAUSE

bw2-ipython.bat

@ECHO OFF
ECHO Setting path to Brightway2 environment
set PATH=C:\bw2-python\envs\bw2\Scripts\;C:\bw2-python\Scripts\;C:\bw2-python\;%PATH%
CALL C:\bw2-python\Scripts\activate.bat bw2
CALL ipython

bw2-notebook.bat

@ECHO OFF
ECHO Setting path to Brightway2 environment
set PATH=C:\bw2-python\envs\bw2\Scripts\;C:\bw2-python\Scripts\;C:\bw2-python\;%PATH%
CALL C:\bw2-python\Scripts\activate.bat bw2
CALL jupyter notebook

Mac OS X

  1. Download the Python 3 Miniconda installer to your Downloads folder.
  2. Open a new Terminal window. The Terminal is Appplications > Utilities > Terminal.app., and enter (copy and paste) the following commands (each line is a separate command):
cd ~/Downloads
chmod +x Miniconda3-latest-MacOSX-x86_64.sh
./Miniconda3-latest-MacOSX-x86_64.sh

This will start the Miniconda installer:

_images/osx-1.png

Press enter to start reading the Miniconda license.

_images/osx-2.png

Press the space bar to go through the license.

_images/osx-3.png

Type yes to agree to the license terms. Next, change the default installation location to /Users/<your user name>/bw2-python.

Warning

You can’t easily move this directory later, as its path is hard-coded in many files. If you make a mistake, it is better to start the installation from the beginning.

Finally, I recommend against (i.e. type no) adding the install location to your path:

_images/osx-4.png

You can always add this line to add the Conda directory to your path later if you want.

  1. Next, run the following long command (in the same terminal window). This is one single long command:

cd ~/bw2-python && bin/conda install -q -y conda && bin/conda update -q conda && bin/conda create -y -n bw2 python=3.4 && source bin/activate bw2 && conda install -q -y wheel && conda update -q wheel pip setuptools && conda install -y numpy ipython ipython-notebook jupyter matplotlib scipy flask lxml requests nose docopt whoosh psutil xlsxwriter xlrd unidecode && pip install --no-cache-dir eight && pip install --no-cache-dir --pre brightway2

This will take a while, but there is a lot to do.

Note

If you get an error message like No packages found in current osx-64 channels matching: conda, then you need to edit the file .condarc in your home directory (/Users/<your user name>/), and add default to the channel list. See also this conda issue.

  1. In the same terminal window, you can enter the IPython interpreter with the command ipython, or run Jupyter notebooks with jupyter notebook.

Note

In each new terminal window, you will need to activate the bw2 environment with the command source ~/bw2-python/bin/activate bw2 before running IPython or the Jupyter notebook server.

You can also download scripts to start both IPython and the Jupyter notebook server. These scripts can be run in the Terminal, or from the Finder, if you associate them with the Terminal app.

Notebook directory

It is best practice to store your notebooks in a different directory outside of the bw2-python directory, and you can copy the notebooks script to this directory. Indeed, you could create subdirectories for each project you will work on.