# Virtual Environment and Poetry Setup Guide
## 1. Create a Virtual Environment
1. Open your terminal and navigate to your project directory.
2. Run the following command to create a virtual environment:
```
python -m venv venv
```
3. Activate the virtual environment:
- On Windows:
```
.\venv\Scripts\activate
```
- On macOS/Linux:
```
source venv/bin/activate
```
## 2. Install Poetry
1. Ensure your virtual environment is activated.
2. Install Poetry using pip:
```
pip install poetry
```
## 3. Initialize Poetry
1. Run the following command to initialize Poetry in your project:
```
poetry init
```
2. Follow the prompts to configure your `pyproject.toml` file. For example:
- Project name: `askme`
- Version: `0.1.0`
- Description: `Askme Django Project`
- Author: `Your Name <your.email@example.com>`
- Python version: `^3.10`
- Add dependencies as needed (e.g., `django`, `redis`, `faiss-cpu`).
## 4. Install Dependencies
1. To install all dependencies listed in `pyproject.toml` and `poetry.lock`, run:
```
poetry install
```
2. To install without development dependencies:
```
poetry install --no-dev
```
## 5. Add New Dependencies
1. To add a new dependency:
```
poetry add package-name
```
2. To add a development dependency:
```
poetry add --dev package-name
```
## 6. Run Commands with Poetry
1. To run a command within the Poetry environment:
```
poetry run python manage.py runserver
```
## 7. Export Dependencies to requirements.txt
1. If you need a `requirements.txt` file for compatibility with other tools:
```
poetry export -f requirements.txt --output requirements.txt
```
## 8. Deactivate Virtual Environment
1. To deactivate the virtual environment, simply run:
```
deactivate
```
## 9. Additional Notes
- Always activate your virtual environment before running Poetry commands.
- Commit both `pyproject.toml` and `poetry.lock` to version control to ensure consistency across environments.
- Use `poetry update` to update dependencies to their latest compatible versions.
# Example pyproject.toml
Below is an example `pyproject.toml` file for your project:
```toml
[tool.poetry]
name = "askme"
version = "0.1.0"
description = "Askme Django Project"
authors = ["Your Name <your.email@example.com>"]
[tool.poetry.dependencies]
python = "^3.10"
django = "^5.0.2"
django-redis = "^5.4.0"
faiss-cpu = "^1.7.4"
redis = "^5.0.1"
[tool.poetry.dev-dependencies]
pytest = "^7.4.0"
black = "^23.12.1"
flake8 = "^7.0.0"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
```
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন