error when running nosetests --with-gae with google cloudsdk installed - python

nosetests --with-gae fails when running under the new cloud sdk. It's looking for dev_appserver.py but looks like it's been renamed to old_dev_appserver.py. I can hack a fix but is there an existing solution? Don't see one on the internets...
$ nosetests --with-gae --gae-lib-root=~/google-cloud-sdk/platform/google_appengine
Traceback (most recent call last):
File "/Users/edahl/src/gmj/bin/nosetests", line 9, in <module>
load_entry_point('nose==1.3.4', 'console_scripts', 'nosetests')()
File "/Users/edahl/src/gmj/lib/python2.7/site-packages/nose/core.py", line 121, in __init__
**extra_args)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 94, in __init__
self.parseArgs(argv)
File "/Users/edahl/src/gmj/lib/python2.7/site-packages/nose/core.py", line 145, in parseArgs
self.config.configure(argv, doc=self.usage())
File "/Users/edahl/src/gmj/lib/python2.7/site-packages/nose/config.py", line 346, in configure
self.plugins.configure(options, self)
File "/Users/edahl/src/gmj/lib/python2.7/site-packages/nose/plugins/manager.py", line 284, in configure
cfg(options, config)
File "/Users/edahl/src/gmj/lib/python2.7/site-packages/nose/plugins/manager.py", line 99, in __call__
return self.call(*arg, **kw)
File "/Users/edahl/src/gmj/lib/python2.7/site-packages/nose/plugins/manager.py", line 167, in simple
result = meth(*arg, **kw)
File "/Users/edahl/src/gmj/lib/python2.7/site-packages/nosegae.py", line 80, in configure
from dev_appserver import fix_sys_path
ImportError: No module named dev_appserver
Here's what I see in my google_appengine directory...
$ ls ~/google-cloud-sdk/platform/google_appengine/
BUGS api_server.py godoc php
LICENSE backends_conversion.py gofmt php_cli.py
README bulkload_client.py google remote_api_shell.py
RELEASE_NOTES bulkloader.py google_sql.py run_tests.py
RELEASE_NOTES.go_sdk demos goroot tools
VERSION download_appstats.py lib wrapper_util.py
_php_runtime.py gen_protorpc.py new_project_template wrapper_util.pyc
_python_runtime.py goapp old_dev_appserver.py
The old /usr/local/google_appengine directory seems to be deprecated... but if I use it I can get things working.
[update]
a manual unittest setup using old_dev_appserver like this does work:
def main(sdk_path, test_path):
sys.path.insert(0, sdk_path)
import old_dev_appserver
old_dev_appserver.fix_sys_path()
suite = unittest.loader.TestLoader().discover(test_path)
unittest.TextTestRunner(verbosity=2).run(suite)

In the end this was pretty silly... needed to expand the user path that's passed to --gae-lib-root
nosetests --with-gae --gae-lib-root=/Users/USERNAME/google-cloud-sdk/platform/google_appengine

On my mac, I get this same error:
After an app engine update
But before I've run the GoogleAppEngineLauncher app since the update
The easy solution is just launch GoogleAppEngineLauncher. This updates the sym links that nosetests needs.
Hopefully that works for you.

You might need to set your path to the lib folder under that directory:
--gae-lib-root=~/google-cloud-sdk/platform/google_appengine/lib
But you might also need to set your PATH variable so it includes the /bin as well:
export PATH=$PATH:~/google-cloud-sdk/platform/google_appengine/bin
If neither of those work for you, try adding the without sandbox switch:
nosetests -s -v --with-gae --without-sandbox

According to the NoseGAE docs the default location it checks for the google-cloud-sdk is in /usr/local/google_appengine.
Moving the google-cloud-sdk folder to /usr/local/google_appengine/google-cloud-sdk/ fixed this issue for me.
http://farmdev.com/projects/nosegae/

Related

importlib.metadata.PackageNotFoundError: No package metadata was found for djoser pyinstaller

Context
I made a Django react app. Now I want to make it a desktop application so that the user does not have type python manage.py runserver and also activate the environment every time. I used pyinstaller. I did all the steps mentioned for django.
Problem
when I run my executable file made from pyinstaller, I got this error
File "manage.py", line 5, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "djoser\__init__.py", line 6, in <module>
File "importlib\metadata\__init__.py", line 955, in version
File "importlib\metadata\__init__.py", line 928, in distribution
File "importlib\metadata\__init__.py", line 518, in from_name
importlib.metadata.PackageNotFoundError: No package metadata was found for djoser
[2200] Failed to execute script 'manage' due to unhandled exception!
What I have done
I have already installed Djoser in the environment and the environment is also activated. I have also tried to add in manage.py file and also in hidden_import lists but nothing changed. I have also tried adding --copy-meta=djoser in the build command but it got even worse error.
How do I fix this error and If there are any better alternative solutions out there? Thanks
Well I have found for myself another solution . To run this django file by creating a batch file
#echo off
set "VENV_NAME=myenv"
set "PROJECT_DIR=C:\path\to\project"
cd /d %~dp0
cd /d %PROJECT_DIR%
call "%VENV_NAME%\Scripts\activate.bat"
python manage.py runserver
manage.exe runserver --norelaod

can't get appengine python sample for flask or django to work

I have downloaded the appengine samples.
When I enter directory python-docs-samples/appengine/standard/django and install it on my appengine project, and then look at the project web page, I get this error:
Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/api/lib_config.py", line 358, in __getattr__
self._update_configs()
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/api/lib_config.py", line 294, in _update_configs
self._registry.initialize()
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/api/lib_config.py", line 165, in initialize
import_func(self._modname)
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_dist/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/base/data/home/apps/s~forcediagnosticsclinic/20180707t052537.410964682053028174/appengine_config.py", line 18, in <module>
vendor.add('lib')
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/ext/vendor/__init__.py", line 44, in add
'No such virtualenv or site directory' % path)
ValueError: virtualenv: cannot access lib: No such virtualenv or site directory
What is going on?
You app config refers to folder called lib and this folder is missing or you forgot to copy it properly. Try to get the same project working on your local computer.
Lenik is right. Specifically, it looks like you didn't do this step in the tutorial:
pip install -r requirements-vendor.txt -t lib/
https://cloud.google.com/python/django/appengine#run_the_app_on_your_local_computer

How to get into the python shell within Odoo 8 environment?

I would like to use the Odoo Framework from the shell.
I installed the module "Shell command backport" (technical name: shell), but I couldn't make it work.
$ ./odoo.py shell --addons-path=/opt/odoo_8/src/linked-addons -d database_name
Traceback (most recent call last):
File "./odoo.py", line 160, in <module>
main()
File "./odoo.py", line 157, in main
openerp.cli.main()
File "/opt/odoo_8/src/OCA/OCB/openerp/cli/__init__.py", line 58, in main
for m in module.get_modules():
File "/opt/odoo_8/src/OCA/OCB/openerp/modules/module.py", line 351, in get_modules
plist.extend(listdir(ad))
File "/opt/odoo_8/src/OCA/OCB/openerp/modules/module.py", line 346, in listdir
return map(clean, filter(is_really_module, os.listdir(dir)))
OSError: [Errno 2] No such file or directory: '/opt/odoo8/openerp/addons'
Where is defined the path /opt/odoo8/openerp/addons? I checked this similar question as well.
If I don't write the addons path in the command the error appears again.
I read the answer of this other question, I tried the module and the script option but they didn't work. What should I do to make it work? Any hint would help.
Check your .opererp_serverrc for the user you are executing the command as. In the users home directory you will find this file. There may be reference to the addons_path. The path it appears to be looking for /opt/odoo8/openerp/addons differs from what you have specified in your command. I would check your config files.

Django manage.py runserver fails with references to strange temporary pip build directories

I am trying to write a script to start the server in my production environment (using apache mod_wsgi):
#!/bin/bash
#activate virtualenv
source ~/.virtualenvs/myproj/bin/activate
# install possibly changed requirements
echo "Checking changed dependencies..."
pip3 install --no-cache-dir -r /opt/myDjangoProj/requirements.txt
deactivate
# run server
echo "Starting django server ..."
#export DJANGO_SETTINGS_MODULE='myDjangoProj.settings.production'
~/.virtualenvs/myproj/bin/python3 /opt/myDjangoProj/manage.py runserver 8000 --settings myDjangoProj.settings.production
However, I alwas get this stacktrace: (installing requirements works fine, so I omit it)
Starting django server ...
Traceback (most recent call last):
File "/opt/myDjangoProj/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/localadm/.virtualenvs/myproj/lib/python3.2/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/localadm/.virtualenvs/myproj/lib/python3.2/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/home/localadm/.virtualenvs/myproj/lib/python3.2/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/localadm/.virtualenvs/myproj/lib/python3.2/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/tmp/pip-build-w8vru4/Django/django/contrib/admin/apps.py", line 22, in ready
File "/tmp/pip-build-w8vru4/Django/django/contrib/admin/__init__.py", line 24, in autodiscover
The directory /tmp/pip-build-w8vru4/ does not actually exist. Do you have any ideas what the problem might be?
First thing is generally we don't need shell scripts when we are using mod_wsgi.
refer https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/ for setting up django with mod_wsgi
Second your working directory not seams to be django project root. switch to django project root or include it in PYTHONPATH.

Issues with supervisord and monit with gunicorn+gevent+pypy

I have a small rest api built in python using Falcon Framework and it runs in a virtual environment with gunicorn + gevent and pypy 2.3 (I successfully installed the pip packages from gevent#pypy-hacks and gevent-on-pypy/pypycore). I wanted to add a "supervisor" for my application so I first installed supervisord and followed the steps to get it up and running.
The first thing I did in the server was to test the command to start the api; it ran successfully and I could use the api without any issues. The command is:
/bin/bash -c 'cd /path/to/project/api && /path/to/project/env/bin/gunicorn -c settings.py my-api:my_api'
Note: in settings.py I set the parameter daemon=False since I saw that supervisors require that the commands are run in the "foreground" and not daemonized.
Once that was working, I went ahead and created the app's /etc/supervisor/conf.d/my_api.conf conf file with the "command" parameter set as the command above I ran successfully. When I tried to start the api through supervisord, it failed, and in the log of the api, the error was:
Traceback (most recent call last):
File "/path/to/project/env/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
worker.init_process()
File "/path/to/project/env/site-packages/gunicorn/workers/ggevent.py", line 185, in init_process
self.patch()
File "/path/to/project/env/site-packages/gunicorn/workers/ggevent.py", line 74, in patch
_sock=s))
File "/path/to/project/env/site-packages/gevent/socket.py", line 240, in __init__
self.hub = get_hub()
File "/path/to/project/env/site-packages/gevent/hub.py", line 169, in get_hub
hub = _threadlocal.hub = hubtype(*args, **kwargs)
File "/path/to/project/env/site-packages/gevent/hub.py", line 268, in __init__
loop_class = _import(self.loop_class)
File "/path/to/project/env/site-packages/gevent/hub.py", line 198, in _import
return _import(path[-1])
File "/path/to/project/env/site-packages/gevent/hub.py", line 210, in _import
x = __import__(module)
ImportError: No module named gevent.core
So, I was surprised that running the command manually did work, but when supervisor tried to run it, the above error was thrown.
After lots of trial and errors, I decided to install monit to see if it could monitor my api, and I did set it up successfully specifying the "start program" parameter as the aforementioned command.
I was surprised that monit throwed the exact same error. So, does this mean that the nature of my api (pypy + gunicorn + gevent) prevents itself from being monitored by any monitor software around there?
Is there something I'm doing wrong when configuring supervisord/monit?
Any help is greatly appreciated.
Turns out that I have the environment var GEVENT_LOOP already exported in my /etc/environment as follows:
export GEVENT_LOOP=pypycore.loop
Since for running gevent on pypy some hacks are needed including the above export.
But I needed to export it manually in the 'start_program' command entry of Monit (at the end I sticked with Monit), so the resulting command is:
/bin/bash -c 'cd /path/to/project/api && export GEVENT_LOOP=pypycore.loop && /path/to/project/env/bin/gunicorn -c settings.py my-api:my_api'

Categories