1
Vote

Imported Django projects reliably fail to be deployed to Azure websites: Exited with Code 3

description

PTVS Django projects that are created via the "From Existing Python Code" option are not able to be published to Azure websites due to what appears to be a bug in the deployment scripts.

Try the following in VS2013:
  1. New Project-> From Existing Python Code -> <Select directory with a sample hello world DJango app>
  2. Under Select Other Features, use the checkbox for "DJango"
  3. Under Python Environments, create a new virtual environment called "env"
  4. Use Install Python Package... -> Use pip to install django into env, make sure that env is the active environment
  5. Run the app to make sure the hello world website runs locally on your machine
  6. Right-click on the project node and select Publish... Import the publishing file from Azure websites, hit Publish.
The publishing will fail with the following error message:

The command ""\env\ \Scripts\python.exe" -c "from djangoImportTester import settings; print(settings.STATIC_URL)" > "C:\Users\JoeBlow\AppData\Local\Temp\tmp9491.tmp"" exited with code 3
The system cannot find the path specified.

The error seems to be that the path to the python executable in the virtual environment is mangled, it should be: "env\Scripts\python.exe" instead of "\env\ \Scripts\python.exe"

For some reason, in Python projects created from scratch, the path to the python executable in the virtual environment is an absolute path at this point, and all is well. However, in PTVS DJango projects created via the "From Existing Python Code" option, it seems to use a mangled relative path where the name of the folder containing the virtual environment has an extra pair of backslashes surrounding it.

Thus far, I have found no work-around. This bug presents massive problems for importing other people's Django projects. From all my testing, it seems that PTVS is currently not a valid option for anyone hoping to deploy existing DJango websites to Azure.

comments

Zooba wrote Feb 12 at 1:09 PM

The workaround for this should be to edit your pyproj file and change the ProjectHome property to "." (I think it is empty right now).

Another possibility is to wait for PTVS 2.1 Alpha, which should be out this week. We've really focused on web this time, and while it is only alpha quality, it should be at least as good as 2.0 in this area. (Also, we'd love feedback from people who know what they're doing - that's the point of releasing early, after all :) )

raybulba wrote Feb 13 at 4:12 PM

Yes you're right, modifying the raw .pyproj file with the text editor and changing the line:
<ProjectHome />
to:
<ProjectHome>.</ProjectHome>
seems to do the trick as a work-around. There's still an extra pair of backslashes surrounding the name of the virtual environment (env) when the command runs, but it doesn't seem to be causing any issues when the path is absolute.

Zooba wrote Feb 13 at 11:14 PM

It generally won't cause issues, though there are cases where it may.

We've released 2.1 Alpha, which should not have the issue (we convert to absolute paths as soon as possible now).

Zooba wrote Feb 13 at 11:20 PM

("cases where it may" was a bit vague. I'm referring to edge cases, where the actual path may be 258 characters long, but the extra ".\" puts it over the limit and things will crash, even though it really shouldn't. In normal usage, there should not be any problems at all :) )