I am trying to register command-line options in Click. Everything is working fine until I add the params argument to the constructor.
class InitCommand(click.Command):
def __init__(self):
super().__init__(
name='init',
short_help='Initialize the needed scaffolding.',
help='something helpful, but longer',
# params=[] ### <-- Works fine
params=[click.Option('--force', default=False)]
)
I get the following error:
Traceback (most recent call last):
File "/usr/local/bin/aquapy", line 11, in <module>
load_entry_point('aquapy-cli', 'console_scripts', 'aquapy')()
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 561, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
return ep.load()
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2291, in load
return self.resolve()
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2297, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/Users/******/__main__.py", line 3, in <module>
from .bootstrap import main
File "/Users/******/bootstrap.py", line 17, in <module>
main.add_command(InitCommand())
File "/Users/******/commands/init_command.py", line 10, in __init__
params=[click.Option('--force', default=False)]
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1460, in __init__
Parameter.__init__(self, param_decls, type=type, **attrs)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1266, in __init__
self._parse_decls(param_decls or (), expose_value)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1533, in _parse_decls
raise TypeError('Name defined twice')
TypeError: Name defined twice
The issue is that click.Option() expects the first argument to a list and is not like the decorator version #click.option().
params=[click.Option(['--force'], default=False)]
Wrapping the command option in a list solved the problem.
Related
I'm attempting to follow this project: https://github.com/MasazI/cnn_depth_tensorflow
The issue is I don't have h5py. So I do pip install h5py. Then I get this:
Traceback (most recent call last):
File "convert_mat_to_img.py", line 4, in <module>
import h5py
ImportError: No module named h5py
MBP-R-006:cnn_depth_tensorflow-master admin2$ pip install h5py
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module>
load_entry_point('pip==10.0.1', 'console_scripts', 'pip')()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2691, in load_entry_point
return ep.load()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2322, in load
return self.resolve()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2328, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python2.7/site-packages/pip/_internal/__init__.py", line 5, in <module>
import logging
File "/usr/local/Cellar/python#2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 626, in <module>
_handlers = weakref.WeakValueDictionary() #map of handler names to handlers
File "/usr/local/Cellar/python#2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 55, in __init__
def remove(wr, selfref=ref(self), _atomic_removal=_remove_dead_weakref):
NameError: global name '_remove_dead_weakref' is not defined
Is my version of python on my OS X messed up/needing modifications? How can I fix this?
EDIT:
I just typed 'pip -V' and this is what I get:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module>
load_entry_point('pip==10.0.1', 'console_scripts', 'pip')()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2691, in load_entry_point
return ep.load()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2322, in load
return self.resolve()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2328, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python2.7/site-packages/pip/_internal/__init__.py", line 5, in <module>
import logging
File "/usr/local/Cellar/python#2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 626, in <module>
_handlers = weakref.WeakValueDictionary() #map of handler names to handlers
File "/usr/local/Cellar/python#2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 55, in __init__
def remove(wr, selfref=ref(self), _atomic_removal=_remove_dead_weakref):
NameError: global name '_remove_dead_weakref' is not defined
I'm trying to implement the pytest plugin mentioned in https://github.com/pytest-dev/pytest/issues/2039, basically this plugin will print all tests that pytest finds:
## pytest_collector.py
import sys
import pytest
class DkPytestCollector(object):
def __init__(self):
self.collected = []
def pytest_collection_modifyitems(self, items):
for item in items:
self.collected.append(item.nodeid)
if __name__ == '__main__':
dkpytest_collector = DkPytestCollector()
directory = sys.argv[1]
pytest.main(['--collect-only', directory], plugins=[dkpytest_collector])
print('\n\nfound:')
for nodeid in dkpytest_collector.collected:
print(nodeid)
however, when I run it I get:
(dk) go|c:\srv\lib\dk> python ..\dkbuild\dkbuild\pytest_collector.py \srv\lib\dk
Traceback (most recent call last):
File "..\dkbuild\dkbuild\pytest_collector.py", line 20, in <module>
pytest.main(['--collect-only', directory], plugins=[dkpytest_collector])
File "c:\srv\venv\dk\lib\site-packages\_pytest\config.py", line 50, in main
config = _prepareconfig(args, plugins)
File "c:\srv\venv\dk\lib\site-packages\_pytest\config.py", line 160, in _prepareconfig
pluginmanager=pluginmanager, args=args)
File "c:\srv\venv\dk\lib\site-packages\pluggy\__init__.py", line 617, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "c:\srv\venv\dk\lib\site-packages\pluggy\__init__.py", line 222, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "c:\srv\venv\dk\lib\site-packages\pluggy\__init__.py", line 216, in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
File "c:\srv\venv\dk\lib\site-packages\pluggy\callers.py", line 196, in _multicall
gen.send(outcome)
File "c:\srv\venv\dk\lib\site-packages\_pytest\helpconfig.py", line 68, in pytest_cmdline_parse
config = outcome.get_result()
File "c:\srv\venv\dk\lib\site-packages\pluggy\callers.py", line 77, in get_result
_reraise(*ex) # noqa
File "c:\srv\venv\dk\lib\site-packages\pluggy\callers.py", line 180, in _multicall
res = hook_impl.function(*args)
File "c:\srv\venv\dk\lib\site-packages\_pytest\config.py", line 943, in pytest_cmdline_parse
self.parse(args)
File "c:\srv\venv\dk\lib\site-packages\_pytest\config.py", line 1108, in parse
self._preparse(args, addopts=addopts)
File "c:\srv\venv\dk\lib\site-packages\_pytest\config.py", line 1071, in _preparse
self.pluginmanager.load_setuptools_entrypoints('pytest11')
File "c:\srv\venv\dk\lib\site-packages\pluggy\__init__.py", line 397, in load_setuptools_entrypoints
plugin = ep.load()
File "c:\srv\venv\dk\lib\site-packages\pkg_resources\__init__.py", line 2405, in load
return self.resolve()
File "c:\srv\venv\dk\lib\site-packages\pkg_resources\__init__.py", line 2411, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "c:\srv\venv\dk\lib\site-packages\_pytest\assertion\rewrite.py", line 212, in load_module
py.builtin.exec_(co, mod.__dict__)
File "c:\srv\venv\dk\lib\site-packages\py\_builtin.py", line 221, in exec_
exec2(obj, globals, locals)
File "<string>", line 7, in exec2
File "c:\srv\venv\dk\lib\site-packages\pytest_cov\plugin.py", line 6, in <module>
from coverage.misc import CoverageException
ImportError: No module named misc
if I pip uninstall pytest-cov everything works (well, except no coverage..)
How do I get this to work without uninstalling pytest-cov?
I am currently trying to run some test on a program, but suddenly I keep getting the same error, no matter what I run it on, be it the program I want to test, a basic tutorial file, an empty file or nothing. The error is :
File "/usr/local/bin/py.test", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 38, in main
config = _prepareconfig(args, plugins)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 117, in _prepareconfig
pluginmanager=pluginmanager, args=args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
_MultiCall(methods, kwargs, hook.spec_opts).execute()
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
return _wrapped_call(hook_impl.function(*args), self.execute)
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
wrap_controller.send(call_outcome)
File "/usr/local/lib/python2.7/dist-packages/_pytest/helpconfig.py", line 28, in pytest_cmdline_parse
config = outcome.get_result()
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
_reraise(*ex) # noqa
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
self.result = func()
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
res = hook_impl.function(*args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 852, in pytest_cmdline_parse
self.parse(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 957, in parse
self._preparse(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 918, in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 501, in load_setuptools_entrypoints
plugin = ep.load()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2088, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/local/lib/python2.7/dist-packages/pytest_bdd/__init__.py", line 3, in <module>
from pytest_bdd.steps import given, when, then
File "/usr/local/lib/python2.7/dist-packages/pytest_bdd/steps.py", line 43, in <module>
from .feature import parse_line, force_encode
File "/usr/local/lib/python2.7/dist-packages/pytest_bdd/feature.py", line 37, in <module>
from . import exceptions
File "/usr/local/lib/python2.7/dist-packages/pytest_bdd/exceptions.py", line 65, in <module>
#six.python_2_unicode_compatible
AttributeError: 'module' object has no attribute 'python_2_unicode_compatible'
I could not find anything relating specifically to this bug in pytest, although it seems to occur in other programs using the six module. I tried reinstalling both six and pytest, but so far no luck. What is the problem and how to solve it?
Here is the result for print(six.__file__, dir(six)):
('/usr/lib/python2.7/dist-packages/six.pyc',
['BytesIO', 'Iterator', 'MAXSIZE', 'Module_six_moves_urllib',
'Module_six_moves_urllib_error', 'Module_six_moves_urllib_parse',
'Module_six_moves_urllib_request', 'Module_six_moves_urllib_response',
'Module_six_moves_urllib_robotparser', 'MovedAttribute', 'MovedModule',
'PY2', 'PY3', 'StringIO', '_LazyDescr', '_LazyModule', '_MovedItems',
'__author__', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__version__', '_add_doc', '_func_closure', '_func_code',
'_func_defaults', '_func_globals', '_import_module', '_iteritems',
'_iterkeys', '_iterlists', '_itervalues', '_meth_func', '_meth_self',
'_moved_attributes', '_urllib_error_moved_attributes',
'_urllib_parse_moved_attributes', '_urllib_request_moved_attributes',
'_urllib_response_moved_attributes', '_urllib_robotparser_moved_attributes',
'add_metaclass', 'add_move', 'advance_iterator', 'b', 'binary_type',
'byte2int', 'callable', 'class_types', 'create_bound_method', 'exec_',
'get_function_closure', 'get_function_code', 'get_function_defaults',
'get_function_globals', 'get_method_function', 'get_method_self',
'get_unbound_function', 'indexbytes', 'int2byte', 'integer_types',
'iterbytes', 'iteritems', 'iterkeys', 'iterlists', 'itervalues', 'moves',
'next', 'operator', 'print_', 'remove_move', 'reraise', 'string_types',
'sys', 'text_type', 'types', 'u', 'unichr', 'with_metaclass'])
The lack of python_2_unicode_compatible and the presence of _iteritems, _itervalues, ... indicates that you are using an old version of Python Six.
Precisely, python_2_unicode_compatible was introduced in September 2014.
You can install a more recent version with pip and virtualenv.
Every time I try to serve my project I get this error:
Traceback (most recent call last):
File "/usr/bin/pserve", line 9, in <module>
load_entry_point('pyramid==1.5.2', 'console_scripts', 'pserve')()
File "/usr/lib/python3.4/site-packages/pyramid-1.5.2-py3.4.egg/pyramid/scripts/pserve.py", line 51, in main
return command.run()
File "/usr/lib/python3.4/site-packages/pyramid-1.5.2-py3.4.egg/pyramid/scripts/pserve.py", line 313, in run
relative_to=base, global_conf=vars)
File "/usr/lib/python3.4/site-packages/pyramid-1.5.2-py3.4.egg/pyramid/scripts/pserve.py", line 344, in loadserver
server_spec, name=name, relative_to=relative_to, **kw)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 255, in loadserver
return loadobj(SERVER, uri, name=name, **kw)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 271, in loadobj
global_conf=global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 296, in loadcontext
global_conf=global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 320, in _loadconfig
return loader.get_context(object_type, name, global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 454, in get_context
section)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 476, in _context_from_use
object_type, name=use, global_conf=global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 406, in get_context
global_conf=global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 296, in loadcontext
global_conf=global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 328, in _loadegg
return loader.get_context(object_type, name, global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 620, in get_context
object_type, name=name)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 646, in find_egg_entry_point
possible.append((entry.load(), protocol, entry.name))
File "/usr/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2320, in load
return self.resolve()
File "/usr/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2326, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/lib/python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/__init__.py", line 1, in <module>
from waitress.server import create_server
File "/usr/lib/python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/server.py", line 23, in <module>
from waitress.channel import HTTPChannel
File "/usr/lib/python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/channel.py", line 28, in <module>
from waitress.task import (
File "/usr/lib/python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/task.py", line 53, in <module>
class ThreadedTaskDispatcher(object):
File "/usr/lib/python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/task.py", line 57, in ThreadedTaskDispatcher
start_new_thread = thread.start_new_thread
AttributeError: 'module' object has no attribute 'start_new_thread'
The weird thing is, the thread module has the attribute start_new_thread
>>> from waitress.compat import (thread, Empty)
>>> thread.start_new_thread
<built-in function start_new_thread>
I started this pyramid project using python 2.7, and I am trying to switch it over to python 3.4.
Things I've tried:
updating the waitress module, it's already up to date
scratching my head
I tried setting up a default pylons project to use mongokit as directed here:
http://namlook.github.com/mongokit/pylons.html
However it gives me the error:
>Traceback (most recent call last):
File "/usr/bin/paster", line 18, in
>command.run()
File "/usr/lib/pymodules/python2.6/paste/script/command.py", line 84, in run
>invoke(command, command_name, options, args[1:])
File "/usr/lib/pymodules/python2.6/paste/script/command.py", line 123, in invoke
>exit_code = runner.run(args)
File "/usr/lib/pymodules/python2.6/paste/script/command.py", line 218, in run
>result = self.command()
File "/usr/lib/pymodules/python2.6/paste/script/serve.py", line 276, in command
>relative_to=base, global_conf=vars)
File "/usr/lib/pymodules/python2.6/paste/script/serve.py", line 313, in loadapp
>**kw)
File "/usr/lib/pymodules/python2.6/paste/deploy/loadwsgi.py", line 204, in loadapp
>return loadobj(APP, uri, name=name, **kw)
File "/usr/lib/pymodules/python2.6/paste/deploy/loadwsgi.py", line 224, in loadobj
>global_conf=global_conf)
File "/usr/lib/pymodules/python2.6/paste/deploy/loadwsgi.py", line 248, in loadcontext
>global_conf=global_conf)
File "/usr/lib/pymodules/python2.6/paste/deploy/loadwsgi.py", line 278, in _loadconfig
>return loader.get_context(object_type, name, global_conf)
File "/usr/lib/pymodules/python2.6/paste/deploy/loadwsgi.py", line 409, in get_context
>section)
File "/usr/lib/pymodules/python2.6/paste/deploy/loadwsgi.py", line 431, in _context_from_use
>object_type, name=use, global_conf=global_conf)
File "/usr/lib/pymodules/python2.6/paste/deploy/loadwsgi.py", line 361, in get_context
>global_conf=global_conf)
File "/usr/lib/pymodules/python2.6/paste/deploy/loadwsgi.py", line 248, in loadcontext
>global_conf=global_conf)
File "/usr/lib/pymodules/python2.6/paste/deploy/loadwsgi.py", line 285, in _loadegg
>return loader.get_context(object_type, name, global_conf)
File "/usr/lib/pymodules/python2.6/paste/deploy/loadwsgi.py", line 561, in get_context
>object_type, name=name)
File "/usr/lib/pymodules/python2.6/paste/deploy/loadwsgi.py", line 587, in find_egg_entry_point
>possible.append((entry.load(), protocol, entry.name))
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 1954, in load
>entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/home/ciferkey/Projects/runnr-site/runnrsite/config/middleware.py", line 11, in
>from runnrsite.config.environment import load_environment
File "/home/ciferkey/Projects/runnr-site/runnrsite/config/environment.py", line 8, in
>import runnrsite.lib.app_globals as app_globals
File "/home/ciferkey/Projects/runnr-site/runnrsite/lib/app_globals.py", line 2, in
>from ekeet.models import register_models
>ImportError: No module named ekeet.models
I haven't been able to find any help anywhere else or even what the module ekeet is. Why might this be happening?
Edit: I figured it out. that must have been the name of the pylons project used in the tutorial. ekeet.modules should really be what ever module you put the register_model in. I wont be so quick to ask next time!
Apparently ekeet just an example. You're supposed to make up your own name. The point is that register_models should be a list of all the modules you want to register. You need to tweak the names for your own needs.