antoinemartin / django-windows-tools

Django application providing management commands to host Django projects in Windows environments
BSD 2-Clause "Simplified" License
51 stars 13 forks source link

With Virtualenv: WindowsError: (2, 'The system cannot find the file specified') #12

Closed bernardotorres closed 7 years ago

bernardotorres commented 9 years ago

My environment: Windows 7 Python 2.7 django-windows-tools from git (updated today)

The service wasn't starting, so I tried running as:

$ python service.py debug

And the following error was issued: WindowsError: (2, 'The system cannot find the file specified')

Debugging a little further, I found that the python interpreter was being wrongly found as %VIRTUALENV_PATH%\python.exe, without the \Scripts\ in the path. For example, if the Virtualenv was in C:\MyVirtualenv\, it assumed the interpreter was in C:\MyVirtualenv\python.exe and not C:\MyVirtualenv\Scripts\python.exe. Therefore it could not run the service.

Searching the web, I found that it is a known problem, but currently not fixed. If assumes python path is sys.exec_prefix, when that is not always the case:

https://hg.python.org/cpython/file/e55f955659bc/Lib/multiprocessing/forking.py

Virtualenv people have claimed no responsibility about it:

https://github.com/pypa/virtualenv/issues/467

One ugly, but working fix would be running this in the beginning of your service.py:

sys.exec_prefix = sys.exec_prefix + "\\Scripts\\"

the-digital-engineer commented 9 years ago

Thank you for your efforts. Maybe your suggestion is not that ugly as you state if we encapsulate it.

try:

whatever raised at you

except WindowsError: sys.exec_prefix+="\Scripts"

retry

This would minimize possible side effects to the cases necessary.

On 2015-02-09 13:30, Bernardo Torres wrote:

One ugly, but working fix would be running this in the beginning of your |service.py|:

|sys.exec_prefix = sys.exec_prefix + "\Scripts\"|

mrbean-bremen commented 7 years ago

It seems that the problem in multiprocessing persists even in Python 3.6 (just checked the code, and I also didn't find a bug for it), so I now added the proposed workaround to service.py. @bernardotorres - if this is still an issue for you, you may check if this solves the problem - I currently don't have an environment to really test this.

mrbean-bremen commented 7 years ago

Shall be fixed with version 0.2.