tipfy nosetest ImportError: No module named fancy_urllib

核能气质少年 提交于 2019-12-07 11:12:27

问题


I am trying to run nosetest using tipfy and google app engine but I keep getting an import error:

From the google_appengine directory I execute the following command (directory contains dev_appserver.py):

nosetests /Users/me/Documents/python/project/ --with-gae --without-sandbox

but I get the following error:

Traceback (most recent call last):
  File "/usr/local/bin/nosetests", line 8, in <module>
    load_entry_point('nose==0.11.4', 'console_scripts', 'nosetests')()
  File "/Library/Python/2.6/site-packages/nose-0.11.4-py2.6.egg/nose/core.py", line 117, in __init__
    **extra_args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 816, in __init__
    self.parseArgs(argv)
  File "/Library/Python/2.6/site-packages/nose-0.11.4-py2.6.egg/nose/core.py", line 134, in parseArgs
    self.config.configure(argv, doc=self.usage())
  File "/Library/Python/2.6/site-packages/nose-0.11.4-py2.6.egg/nose/config.py", line 323, in configure
    self.plugins.configure(options, self)
  File "/Library/Python/2.6/site-packages/nose-0.11.4-py2.6.egg/nose/plugins/manager.py", line 270, in configure
    cfg(options, config)
  File "/Library/Python/2.6/site-packages/nose-0.11.4-py2.6.egg/nose/plugins/manager.py", line 93, in __call__
    return self.call(*arg, **kw)
  File "/Library/Python/2.6/site-packages/nose-0.11.4-py2.6.egg/nose/plugins/manager.py", line 161, in simple
    result = meth(*arg, **kw)
  File "build/bdist.macosx-10.6-universal/egg/nosegae.py", line 84, in configure
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 51, in <module>
    import fancy_urllib
ImportError: No module named fancy_urllib

I can load the tipfy hello_world project without any errors and I have other app engine projects on the same machine, all running fine.

Using a mac os x 10.6.6 and I have both nose and nosegae installed. I have also tried to execute the same command from within the /Users/me/Documents/python/project/ folder but I get the same result


回答1:


I had the same problem and here is my quick fix:

Modify this file "/usr/local/bin/dev_appserver.py"

......
if version_tuple == (2, 4):
  sys.stderr.write('Warning: Python 2.4 is not supported; this program may '
                   'break. Please use version 2.5 or greater.\n')
#Start Change
#DIR_PATH = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
DIR_PATH = "/usr/local/google_appengine"
#End Change

SCRIPT_DIR = os.path.join(DIR_PATH, 'google', 'appengine', 'tools')
......

Works for me so far.




回答2:


Try to run it with option:

--gae-lib-root=/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine

and please show Python sys.path.




回答3:


I also ran into this problem using Nose / NoseGAE. I had no luck with trying various --gae-lib-root values, but I did eventually have luck patching dev_appserver.py (located in /usr/local/google_appengine/google/appengine/tools/ in my MacOS install) as follows:

...
try:
  import distutils.util
except ImportError:
  pass

# ----- start of new code -----
import os, sys

DIR_PATH = '/usr/local/google_appengine'
EXTRA_PATHS = [
    DIR_PATH,
    os.path.join(DIR_PATH, 'lib', 'antlr3'),
    os.path.join(DIR_PATH, 'lib', 'django_0_96'),
    os.path.join(DIR_PATH, 'lib', 'fancy_urllib'),
    os.path.join(DIR_PATH, 'lib', 'ipaddr'),
    os.path.join(DIR_PATH, 'lib', 'webob'),
    os.path.join(DIR_PATH, 'lib', 'yaml', 'lib'),
    os.path.join(DIR_PATH, 'lib', 'simplejson'),
    os.path.join(DIR_PATH, 'lib', 'graphy'),
]
sys.path = EXTRA_PATHS + sys.path
# ----- end of new code -----

import dummy_thread
...

This closely follows some code in appcfg.py (fix_sys_paths()) mentioned in GAE issue ticket #3597. I suspect the issue lies in how Nose sets up the execution path, although I can't prove so at the moment.




回答4:


It turns out that it is because of a UI bug when you set up the "Python Path" in the Preferences of GoogleAppengineLuncher. It needs an Enter to confirm the setting:

    sudo port install python2.7

Then set the "Python Path" to

    /opt/local/bin/python2.7

Enter to confirm

See here




回答5:


If you are running stand alone scripts then before using any appengine stuff you gotta link to dirs

import sys
sys.path.append('/usr/local/google_appengine/')
sys.path.append('/usr/local/google_appengine/lib')
sys.path.append('/usr/local/google_appengine/lib/yaml/lib/')
if 'google' in sys.modules:
    del sys.modules['google']



回答6:


Nowadays (2016) GAE Python recommends loading the project libraries in the file at the root level entitled "appengine_config.py".

Thus, if you are still facing some obnoxious issues, pls make sure to also add the os dir path to load the library folder "lib" (as can be seen in my code below):

"""`appengine_config` gets loaded when starting a new application instance."""
import os
from google.appengine.ext import vendor
# insert `lib` as a site directory so our `main` module can load
# third-party libraries, and override built-ins with newer
# versions.
vendor.add(os.path.join(os.path.dirname(__file__), 'lib'))

After I did the above, I was able to run my tests successfully from IntelliJ (PyCharm). Furthermore, please notice my test settings setup on intelliJ (PyCharm)

Hope the above can help some Python GAE devs since I had some challenges in getting the NoseGAE simple setup to work. Take care!



来源:https://stackoverflow.com/questions/5210584/tipfy-nosetest-importerror-no-module-named-fancy-urllib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!