question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why i'm getting `TypeError: 'module' object is not callable`?

See original GitHub issue

This is my main.py.

.
.
.

try:
    cmd_type = sys.argv[1]

except IndexError:
    cmd_type = "run"

if cmd_type == "manage":
    call_command(*sys.argv[2:])

elif cmd_type == "run":
    call_command("runserver")

.
.
.

Here i ran command to see my migrations for django app built by shiv even this command exited successfully but with that TypeError i cannot use exit code of command. what am i missing? or what can i do to handle that?

shiv on  shiv [$?] via shiv
[I] ➜ ./myapp-1.6.3-3a380acb.pyz manage showmigrations auth
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
 [X] 0009_alter_user_last_name_max_length
 [X] 0010_alter_group_name_max_length
 [X] 0011_update_proxy_permissions
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "./myapp-1.6.3-3a380acb.pyz/__main__.py", line 3, in <module>
  File "./myapp-1.6.3-3a380acb.pyz/_bootstrap/__init__.py", line 179, in bootstrap
  File "./myapp-1.6.3-3a380acb.pyz/_bootstrap/__init__.py", line 33, in run
TypeError: 'module' object is not callable

shiv on  shiv [$?] via shiv
[I] ➜ echo $?
1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
lorencarvalhocommented, Mar 12, 2020

Hi @yzdann, thanks this is helpful.

I think the crux of your issue is on the last line of your build.sh script, where you invoke shiv:

shiv --site-packages dist --compressed -E -p "/usr/bin/env $PYTHON" -o $BUILD_NAME -e myapp.main

The string you pass to -e must be callable, and the snippet you show of main.py indicates it’s a script, e.g. something you would run like python3 ./myapp/main.py. If your application defines any console_script (doc) entries you can use the -c argument.

All you need to do is sequester the runnable logic in main.py into a function. So, if your script is:

try:
    cmd_type = sys.argv[1]
except IndexError:
    cmd_type = "run"
if cmd_type == "manage":
    call_command(*sys.argv[2:])
elif cmd_type == "run":
    call_command("runserver")

Change it to:

def cli():
    try:
        cmd_type = sys.argv[1]
    except IndexError:
        cmd_type = "run"
    if cmd_type == "manage":
        call_command(*sys.argv[2:])
    elif cmd_type == "run":
        call_command("runserver")

if __name__ == "__main__":
    cli()

And then change the string you pass to -e to be myapp.main:cli.

Let me know if that helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: 'module' object is not callable - Stack Overflow
It says module object is not callable , because your code is calling a module object. A module object is the type of...
Read more >
TypeError: module object is not callable [Python Error Solved]
To put it simply, the "TypeError: 'module' object is not callable" error means that modules cannot be called like functions or methods. How...
Read more >
What is "typeerror: 'module' object is not callable"
This error statement TypeError: 'module' object is not callable is raised as you are being confused about the Class name and Module name....
Read more >
Typeerror module object is not callable : How to Fix?
Typeerror module object is not callable (Solution): ... The Golden rule to fix this error is to invoke the respective python class or...
Read more >
TypeError: 'module' object is not callable in Python | bobbyhadz
The Python "TypeError: 'module' object is not callable" occurs when we import a module as import some_module but try to call it as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found