Organice / django-organice

All-in-one collaboration solution. For non-profit organizations, sports clubs, small to medium-sized businesses. Nice, very nice,
https://organice.io
Apache License 2.0
48 stars 16 forks source link

"OSError: [WinError 193] %1 is not a valid Win32 application" when calling organice-setup #9

Closed mkane848 closed 8 years ago

mkane848 commented 8 years ago

Following the documentation and calling "organice-setup example", I get:

(env) U:\organice\intranet>organice-setup example
Generating project example ...
Traceback (most recent call last):
  File "U:\organice\env\Scripts\organice-setup-script.py", line 9, in <module>
    load_entry_point('django-organice==0.3.dev1', 'console_scripts', 'organice-setup')()
  File "u:\organice\env\lib\site-packages\organice\bin\organice_setup.py", line 577, in startproject
    _create_project()
  File "u:\organice\env\lib\site-packages\organice\bin\organice_setup.py", line 123, in _create_project
    code = call(['django-admin.py', 'startproject', projectname, '.'])
  File "c:\users\mkane\appdata\local\programs\python\python35-32\Lib\subprocess.py", line 560, in call
    with Popen(*popenargs, **kwargs) as p:
  File "c:\users\mkane\appdata\local\programs\python\python35-32\Lib\subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "c:\users\mkane\appdata\local\programs\python\python35-32\Lib\subprocess.py", line 1220, in _execute_child
    startupinfo)
OSError: [WinError 193] %1 is not a valid Win32 application

I'm on Windows 10 and using Python 3.5

bittner commented 8 years ago

Looks like this is an issue specific to Windows:

code = call(['python', 'django-admin.py', 'startproject', projectname, '.'])

If you're just testing and you don't care about reusability edit your u:\organice\env\lib\site-packages\organice\bin\organice_setup.py directly.

The python executable must be in your PATH. See the StackOverflow question for solutions otherwise.

On Unix this works because the django-admin.py script is made executable using file permissions.

mkane848 commented 8 years ago

Alright, made the change to organice_setup and I'm now getting a different error.

Generating project example ...
python: can't open file 'django-admin.py': [Errno 2] No such file or directory

django-admin.py is in fact located in my env\Scripts\ folder

bittner commented 8 years ago

Can you try setting the path instead, i.e. restore the call code as before (no python call) and try as suggested in StackOverflow question 17836416? This looks like the appropriate approach.

mkane848 commented 8 years ago

My path is set at C:\Users\mkane\AppData\Local\Programs\Python\Python35-32\Scripts. I've gotten DjangoCMS to run on this environment, if that helps at all

bittner commented 8 years ago

Alright, so django CMS' scripts are at the same location as django Organice' scripts? (Which django CMS commands do you execute that work?) If not, try to understand what's the difference. The problem must be there.

Let me know about your findings, so I can incorporate either some changes to the code or provide hints for Windows users in the documentation. Thank you!

bittner commented 8 years ago

@mkane848 Mike, if there is anything that you can share what solved your problem please let us know.

mkane848 commented 8 years ago

I actually didn't get around to solving the problem, just ended up going back to regular DjangoCMS. I'll keep messing with Organice to see if I can figure it out still

mkane848 commented 8 years ago

I believe the issue is with Windows. Even with the path set, I still have to copy the path to where my django-admin.py file is. So I believe the best tip to put in documentation for Windows users is that if your Path is properly set on Windows but it still can't find django-admin.py, go to line 123 in organice_setup.py and change it to:

 code = call(['python', r"<path to virtualenv folder>\Scripts\django-admin.py", 'startproject', projectname, '.'])

Which allows the setup script to run properly to completion.

bittner commented 8 years ago

Thank you, @mkane848, for this helpful feedback!

I still think we should try to solve the problem. Editing the source code is not a solution. Our situation is especially odd, you'd have to go into the sources installed in your virtualenv's site-packages, not nice.

If the PATH environment variable is set correctly, but django-admin.py is not found then something must be wrong with the environment. I suspect the call function call results in a new environment which points to the wrong python binary, because the PATH environment variable is not set correctly.

I've done a lucky 30-seconds googling (with duckduckgo) and found a hint on assoc and ftype. That could or could not be a helpful puzzle piece. (Actually, this could be used to solve the very first complaint on the command line, where the Windows cmd interpreter complains that the .py file is "not a valid Win32 application".)

Can you try printing the contents of the PATH variable with the call function? That should make it clear if I'm suspecting the right culprit.

EDIT: It's actually logical that you have to use the full path with the python call. It's just a parameter to the Python interpreter. It's not even Windows' fault that python doesn't find the django-admin.py script, actually Windows does find the script as the first error trace above demonstrates, but it must be used as a command, i.e. as the first argument on the command line, not a parameter.

This is also discussed (and solved) in this StackOverflow question. Interestingly, the Django documentation is talking about a django-admin.exe (NOTE: .exe) file. Maybe we should simply use django-admin instead of django-admin.py? This would find the .exe on Windows, and the .py script on Unixes.

bittner commented 8 years ago

@mkane848 can you try?

    code = call(['django-admin', 'startproject', projectname, '.'])

This works on Linux, and will most probably work on your Windows system too. I'll change that in the current development version.

mkane848 commented 8 years ago

Confirming that it works on Windows. Nice catch with the .exe/.py switch!

bittner commented 8 years ago

Thank you for reporting the issue and your trouble shooting!