Skip to content

🐛 Fix app creation command to use the current Python executable#30

Closed
hv-tamiri wants to merge 1 commit into
mindoffwork:rootfrom
hv-tamiri:bug/django-app-creation-venv-issue
Closed

🐛 Fix app creation command to use the current Python executable#30
hv-tamiri wants to merge 1 commit into
mindoffwork:rootfrom
hv-tamiri:bug/django-app-creation-venv-issue

Conversation

@hv-tamiri

Copy link
Copy Markdown

This PR fixes an issue encountered while creating a Django app using the automated setup provided in the repository.

Previously, the implementation used a hardcoded "python" command while invoking manage.py startapp. This caused failures in environments where:

  • Multiple Python versions are installed, or
  • A virtual environment is active but not mapped to the default python command

Root Cause

The command was relying on the system’s default python interpreter instead of the currently active Python environment.


Fix Implemented

Replaced the hardcoded "python" with sys.executable to ensure the command always uses the currently active Python interpreter.
import sys

subprocess.run(
    [sys.executable, "manage.py", "startapp", self.app_name, self.app_dir],
    check=True,
)

Impact

  • Ensures compatibility across environments with multiple Python versions
  • Properly respects virtual environments
  • Prevents app creation failures due to interpreter mismatch
  • Improves reliability of the automation script

Testing

  • Verified app creation in:

    • Global Python setup
    • Virtual environment (venv)
  • Confirmed successful execution of startapp without errors


Additional Notes

This is a minimal and backward-compatible fix that improves environment consistency without affecting existing functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants