# Installation

This page provides detailed instructions for installing PyBaseball, a Python package for retrieving and analyzing baseball data from various sources including Baseball Reference, Baseball Savant, and FanGraphs. The installation process is straightforward and can be completed using standard Python package management tools.

For information about how to use PyBaseball after installation, see the [Basic Usage](/content/jldbc/pybaseball/1.2-basic-usage/index.html) page.

## System Requirements

- Python 3.8 or later (Python 3.8, 3.9, 3.10, and 3.11 are officially supported)
- Pip package manager

Sources: [setup.py62-66](https://github.com/jldbc/pybaseball/blob/114d72a2/setup.py#L62-L66)

## Installation Methods

### Method 1: Using pip (Recommended)

The simplest way to install PyBaseball is via pip:

```
pip install pybaseball
```

This method automatically installs PyBaseball along with all required dependencies.

### Method 2: Installation from Source

For the most up-to-date version or for development purposes, install directly from the GitHub repository:

```
git clone https://github.com/jldbc/pybaseball
cd pybaseball
pip install -e .
```

The `-e` flag creates an "editable" installation, which is useful if you plan to modify the code.

Sources: [README.md11-23](https://github.com/jldbc/pybaseball/blob/114d72a2/README.md?plain=1#L11-L23)

## Installation Process

The following diagram illustrates the PyBaseball installation process:

```
Standard Method

Development Version

Yes

No

Start Installation

Ensure Python 3.8+ is installed

Choose Installation Method

pip install pybaseball

git clone https://github.com/jldbc/pybaseball

cd pybaseball

pip install -e .

Dependencies automatically installed:
- numpy
- pandas
- beautifulsoup4
- requests
- etc.

Verify Installation:
Import and test a function

Installation Successful?

Optional: Enable Caching
from pybaseball import cache
cache.enable()

Troubleshoot Common Issues:
- Python version
- Dependency conflicts
- Network errors
```

Sources: [README.md11-25](https://github.com/jldbc/pybaseball/blob/114d72a2/README.md?plain=1#L11-L25) [setup.py84-95](https://github.com/jldbc/pybaseball/blob/114d72a2/setup.py#L84-L95)

## Dependencies

PyBaseball relies on several Python packages that are automatically installed when using pip:

| Package | Minimum Version | Purpose |
| --- | --- | --- |
| numpy | 1.13.0 | Numerical computing |
| pandas | 1.0.3 | Data manipulation and analysis |
| beautifulsoup4 | 4.4.0 | HTML parsing |
| requests | 2.18.1 | HTTP requests |
| lxml | 4.2.1 | XML and HTML processing |
| pyarrow | 1.0.1 | Efficient data serialization for caching |
| pygithub | 1.51 | GitHub API interaction |
| scipy | 1.4.0 | Scientific computing |
| matplotlib | 2.0.0 | Data visualization |
| tqdm | 4.50.0 | Progress bars |
| attrs | 20.3.0 | Class attributes |

Sources: [setup.py84-95](https://github.com/jldbc/pybaseball/blob/114d72a2/setup.py#L84-L95)

## Verifying Installation

To verify that PyBaseball has been installed correctly, run a simple test query:

```
from pybaseball import playerid_lookup
playerid_lookup('trout', 'mike')
```

If the installation was successful, this should return a DataFrame with Mike Trout's player IDs across different baseball data systems.

## Optional Configuration: Enabling Caching

PyBaseball includes a caching system that improves performance by storing previously retrieved data. Caching is disabled by default but can be enabled as follows:

```
from pybaseball import cache
cache.enable()
```

For more details on the caching system, see the [Caching System](/content/jldbc/pybaseball/5.2-caching-system/index.html) page.

Sources: [README.md158-170](https://github.com/jldbc/pybaseball/blob/114d72a2/README.md?plain=1#L158-L170)

## Troubleshooting Common Installation Issues

### ImportError: No module named pybaseball

Ensure that PyBaseball is installed in the Python environment you're currently using. You may need to specify the Python interpreter when installing:

```
python3 -m pip install pybaseball
```

### Dependency Conflicts

If you encounter dependency conflicts, consider using a virtual environment:

```
python -m venv pybaseball_env
source pybaseball_env/bin/activate  # On Windows: pybaseball_env\Scripts\activate
pip install pybaseball
```

### Multiprocessing Errors

If you get errors related to multiprocessing (especially on Windows or macOS), wrap your code in a main function:

```
if __name__ == '__main__':
    from pybaseball import statcast
    data = statcast(start_dt="2021-04-01", end_dt="2021-04-02")
```

Sources: [README.md183-192](https://github.com/jldbc/pybaseball/blob/114d72a2/README.md?plain=1#L183-L192)

### Stale Cache Issues

If you're not getting expected results due to cached data:

```
from pybaseball import cache
cache.purge()  # Clears the cache completely
```

Sources: [README.md174-181](https://github.com/jldbc/pybaseball/blob/114d72a2/README.md?plain=1#L174-L181)

### Permission Errors During Installation

If you encounter permission errors when installing:

```
pip install --user pybaseball  # Install for current user only
```

Or use a virtual environment as described above.
