nephila / djangocms-installer

Console wizard to bootstrap django CMS projects
https://djangocms-installer.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
177 stars 78 forks source link

Does not look for django-admin.py in PATH #309

Closed matthijskooijman closed 6 years ago

matthijskooijman commented 6 years ago

For some reason, the installer looks for django-admin.py in (only) the directory where python is installed, which presumably works when python is installed using virtualenv and then pip installs django.

However, when running a system-wide python from /usr/bin, with pip installations going into /usr/local/bin/ or ~/.local/bin, this fails to find django-admin.py:

$ djangocms -p . mysite                                                
Creating the project                                                   
Please wait while I install dependencies                                                          
Dependencies installed                                                                           
Creating the project                                                                                                 
/usr/bin/python3: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory
The installation has failed.
$ which django-admin.py
/home/matthijs/.local/bin/django-admin.py

The code for this lives here: https://github.com/nephila/djangocms-installer/blob/develop/djangocms_installer/django/__init__.py#L45-L56

By changing this to, for example, the following, the current search is preserved and any file found is started using an explicit python call, but when no file is found there, the system PATH is used for a "django-admin.py" command instead.

start_cmds = [os.path.join(os.path.dirname(sys.executable), 'django-admin.py')]
start_cmd_pnodes = ['Scripts']
start_cmds.extend([
    os.path.join(os.path.dirname(sys.executable), pnode, 'django-admin.py')
    for pnode in start_cmd_pnodes
])
start_cmd = ['django-admin.py']
for p in start_cmds:
    if os.path.exists(p):
        start_cmd = [sys.executable, p]
        break
cmd_args = ' '.join(start_cmd + ['startproject'] + args)
yakky commented 6 years ago

The use of a virtualenv is a prerequisite for djangocms-installer. Supporting other layouts in a multi-platform way has proven overly complex and unreliable and I have no plan to add it. Help welcome to support other layouts, as long as they don't break Windows support

matthijskooijman commented 6 years ago

With the changes proposed above, the installer seems to work (at least run without errors) in my environment, so that might be good to add. I'm not actually working with django-cms currently, so I can't provide more support than this, so if you want to close this, feel free.

yakky commented 6 years ago

@matthijskooijman thanks for the suggestion. after a few tests, it seems a sensible solution for your use case that does not breaks the other environments

313 implements the suggested code

yakky commented 6 years ago

Closed via #313