Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't load package in Azure WebJobs #224

Closed
mawah opened this issue Sep 27, 2016 · 3 comments
Closed

Can't load package in Azure WebJobs #224

mawah opened this issue Sep 27, 2016 · 3 comments

Comments

@mawah
Copy link
Member

mawah commented Sep 27, 2016

I'd like to create a Python Azure WebJob that uses this module to read/write from Azure Blob Storage. I included the azure-storage package in my App Service's requirements.txt file:

azure==2.0.0rc6
azure-storage>=0.33.0

...and the package installs via pip without errors during App Service deployment. After install, the directory structure under D:\home\site\wwwroot\env\Lib\site-packages\azure\storage looks exactly as I would expect. However, when I try to import BlockBlobService from azure.storage.blob:

import sys
sys.path.append('D:\\home\\site\\wwwroot\\env\\Lib\\site-packages')
from azure.storage.blob import BlockBlobService

...something seems to go wrong with the relative imports, at least as far as I can tell from the error message:

[09/27/2016 17:51:09 > 775106: SYS INFO] Status changed to Initializing
[09/27/2016 17:51:09 > 775106: SYS INFO] Run script 'run.py' with script host - 'PythonScriptHost'
[09/27/2016 17:51:09 > 775106: SYS INFO] Status changed to Running
[09/27/2016 17:51:10 > 775106: ERR ] Traceback (most recent call last):
[09/27/2016 17:51:10 > 775106: ERR ]   File "run.py", line 11, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from azure.storage.blob import BlockBlobService
[09/27/2016 17:51:10 > 775106: ERR ]   File "D:\home\site\wwwroot\env\Lib\site-packages\azure\storage\blob\__init__.py", line 15, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from .models import (
[09/27/2016 17:51:10 > 775106: ERR ]   File "D:\home\site\wwwroot\env\Lib\site-packages\azure\storage\blob\models.py", line 15, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from .._common_conversion import _to_str
[09/27/2016 17:51:10 > 775106: ERR ]   File "D:\home\site\wwwroot\env\Lib\site-packages\azure\storage\_common_conversion.py", line 22, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from .models import (
[09/27/2016 17:51:10 > 775106: ERR ]   File "D:\home\site\wwwroot\env\Lib\site-packages\azure\storage\models.py", line 23, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from ._error import (
[09/27/2016 17:51:10 > 775106: ERR ]   File "D:\home\site\wwwroot\env\Lib\site-packages\azure\storage\_error.py", line 15, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from ._common_conversion import _to_str
[09/27/2016 17:51:10 > 775106: ERR ] ImportError: cannot import name '_to_str'
[09/27/2016 17:51:10 > 775106: SYS INFO] Status changed to Failed
[09/27/2016 17:51:10 > 775106: SYS ERR ] Job failed due to exit code 1

FWIW, other packages are installing properly with the same approach. I'm not 100% certain from the error message that this is an azure-storage package-specific issue, but if anyone here knows the cause or can suggest a workaround, I'd be very appreciative.

@rambho
Copy link

rambho commented Sep 28, 2016

Hi @mawah,
The ImportError: cannot import name usually stems from a cyclic dependency, and it may very well be related to an issue with the relative import.

Are you by chance running this file with the python -m flag?
Nonetheless, I will investigate and see if there is possible resolution for this issue on our end.

Thanks!

@rambho
Copy link

rambho commented Sep 29, 2016

Hi @mawah,
I was able to repro this error message and fix it by either adding the six module to requirements.txt or manually by pip install six.

Let me know if that works for you.

However, there is also a known issue with azure storage deployment with WebApps/Jobs, see #219.

@mawah
Copy link
Member Author

mawah commented Sep 30, 2016

Hi Rambo,

Thanks for the suggestion to require the six module -- I have it working! Is there any way to catch the missing dependency earlier (e.g. during installation) or with a more informative error message?

FYI, re: the cryptography dependency issue you referenced, I found a workaround by noticing that WebJobs will only accept wheels with an ABI tag of "none":

import pip
print(pip.pep425tags.get_supported())
[09/28/2016 17:08:30 > 775106: INFO] [('cp34', 'none', 'win32'), ('cp34', 'none', 'any'), ('cp3', 'none', 'any'), ('cp33', 'none', 'any'), ('cp32', 'none', 'any'), ('cp31', 'none', 'any'), ('cp30', 'none', 'any'), ('py34', 'none', 'any'), ('py3', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]

Most modern wheels do not have that ABI tag, which is why pip will not accept the wheels for cryptography==1.5.2. Fortunately the wheel file can simply be renamed, e.g.

cryptography-1.5.2-cp34-cp34m-win32.whl =>cryptography-1.5.2-cp34-none-win32.whl

...and included along with a corresponding entry in the requirements.txt file. Will mention it on the other issue.

@mawah mawah closed this as completed Sep 30, 2016
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

No branches or pull requests

2 participants