简体   繁体   中英

TypeError: 'module' object is not callable when running pip3 with sudo on CentOS 7

If I run pip3 with sudo, it gives the following error message:

[idwwwoqq808@centos7 ~]$ sudo pip3 -V
Traceback (most recent call last):
  File "/bin/pip3", line 16, in <module>
    sys.exit(main())
TypeError: 'module' object is not callable

But it works fine if I run pip3 as regular user:

[idwwwoqq808@centos7 ~]$ pip3 -V
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

I've tried upgrading pip3 for all users using pip3 install --upgrade but it just doesn't work. How can I solve this problem?

I'm asking this because I want to install a package and the process will stop with error since regualr pip3 has no access to /usr directory.

Source code of pip3 is as follows:

#!/usr/bin/python3

# -*- coding: utf-8 -*-
import re
import sys

try:
    from pip import main
except ImportError:
    # user has most probably upgraded pip in their home
    # so let them run it anyway until ~/.local/bin makes it in front of the PATH
    from pip._internal import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

I've successfully installed that package with '--User' option. Thanks everyone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM