Skip to content

Python Setup Instructions

Why using virutal environments?

Using virtual environments in the context of the BabelBetes project is highly recommended when installing modules via pip install -r requirements.txt. This ensures that all dependencies listed in the requirements.txt file are isolated to the BabelBetes project, preventing conflicts with other projects that might require different versions of the same modules. It also keeps your system-wide Python environment clean, and allows easy replication of the project’s environment on other systems, ensuring consistency across development setups.

macOS

We recommend using both pyenv and virtualenv packages to manage virtual enviroments. - pyenv manages multiple Python versions: This allows you to install and switch between different versions of Python system-wide. - virtualenv creates isolated project environments: Each virtual environment has its own set of Python packages, isolating your project's dependencies and preventing conflicts with other projects or the system-wide Python installation. - This allows switching between different versions of Python without affecting your current projects and working on projects that have different requirements (e.g., an older version of modules such as pandas).

  1. Installing pyenv
  2. Install brew (if you don’t have it yet): https://docs.brew.sh/Installation
  3. Install pyenv using brew: bash brew install pyenv

  4. Installing Python

  5. List available versions using: bash pyenv versions
  6. Install a specific version using: bash pyenv install <version> # e.g. pyenv install 3.9.6
  7. Note: You may need to install these dependencies before installing Python: bash brew install openssl readline sqlite3 xz zlib

  8. Setting the global Python version

  9. Set a specific version as the global version using: bash pyenv global <version> # e.g. pyenv global 3.9.6

  10. Using pyenv with your shell (here, zsh)

  11. Add pyenv to your shell configuration: bash echo 'eval "$(pyenv init --path)"' >> ~/.zprofile echo 'eval "$(pyenv init -)"' >> ~/.zshrc

  12. Installing the pyenv-virtualenv extension

  13. This extension allows you to create virtual environments using pyenv: bash brew install pyenv-virtualenv

  14. Creating a virtual environment

  15. Create a virtual environment for a specific Python version and name: bash pyenv virtualenv <version> <name> # e.g. pyenv virtualenv 3.9.6 my_env

  16. Activating and deactivating a virtual environment (in shell)

  17. Activate a virtual environment: bash pyenv activate <environment name> # e.g. pyenv activate my_env

  18. Installing Python modules from a requirements.txt

  19. Make sure your virtual environment is activated (see step 7).
  20. Install the required modules using: bash pip install -r requirements.txt

Windows

  1. Ensure Python is installed:
python --version

If needed, install Python and ensure “Add Python to PATH” is checked.

  1. Navigate to your project directory: cd C:\path\to\your\project
  2. Create a virtual environment named babelbetespython -m venv babelbetes
  3. Activate the babelbetes virtual environment:
babelbetes\Scripts\activate
  1. Install packages from requirements.txt :
pip install -r requirements.txt
  1. Install packages from requirements.txt :
pip install -r requirements.txt
  1. Deactivate the virtual environment:
deactivate

That’s it! Now you’re working with the babelbetes virtual environment and can easily activate or switch to it when needed.