Skip to content

ModuleNotFoundError

Tuana Durmayüksel edited this page Jan 22, 2025 · 1 revision

Why am I receiving ModuleNotFoundError: No module named 'schnapsen'?

The ModuleNotFoundError: No module named 'schnapsen' occurs when the Python interpreter cannot find the Schnapsen package in your environment. This can happen if the package is not installed or if it is installed in the wrong environment. To resolve this issue, follow the steps below:

1. Ensure Python Version Compatibility

  • Check if your Python version is compatible with the Schnapsen package (Python 3.10 or higher is recommended).
  • Open your terminal or command prompt and run:
    python --version
    (Use python3 --version if you are specifically using Python 3).
  • If your version is lower than 3.10, you may need to upgrade your Python version.

2. Verify Git Installation

Before cloning the repository from GitHub, ensure Git is installed on your system. Git is needed to clone repositories from GitHub.

  • To check if Git is installed, run:
    git --version
  • If Git is not installed, download and install it from Git Downloads, following the installation instructions for your operating system.

3. Check and Activate Virtual Environment

Python virtual environments help manage dependencies specific to projects. Ensure you are working within the correct virtual environment where the Schnapsen package is installed.

  • Check if you are in an active virtual environment by looking at your terminal prompt. If you are inside a virtual environment, it will typically show its name, like project_is or venv.

  • Example of an active virtual environment: image

  • To activate a virtual environment:

    • On Linux/MacOS: source venv/bin/activate
    • On Windows: venv\Scripts\activate
    • Replace venv with your environment's name (e.g., project_is if you followed the instructions on the Getting Started with the Schnapsen Platform page).
  • If using Conda, activate the environment with:

    conda activate [environment name]

4. Clone the Repository

  • Clone the Schnapsen repository from GitHub to your local machine:
    git clone https://github.com/intelligent-systems-course/schnapsen

5. Install the Schnapsen Package

  • Navigate to the root directory of the cloned repository:
    cd schnapsen
  • Ensure you are inside the correct virtual environment and install the package in editable mode:
    pip install -e .

6. Verify Package Installation

  • After installation, check that the schnapsen package is correctly installed by running:
    python -m pip show schnapsen
    This command should return details about the installed package.

7. Check for Dependency Conflicts

  • Sometimes, conflicts with other installed packages can cause issues. To check for dependency conflicts, run:
    pip check
  • If conflicts are found, you may need to upgrade or downgrade specific packages:
    pip install [package]==[version]

8. Reattempt Running Your Code

  • After following the above steps, try running your code again. Ensure that you are using the same terminal and virtual environment where the Schnapsen package was installed.

9. Check System Path (If Issues Persist)

  • If you continue to encounter issues, verify that your system’s PATH includes the Python executable and scripts directory:
    • On Linux/MacOS: Run echo $PATH
    • On Windows: Run echo %PATH%

By following these steps, you should resolve the ModuleNotFoundError and successfully run your code with the Schnapsen package.