48

I am new in Python, I wanna install Jupyter Notebook in my console I enter the following:

pip3 install --upgrade pip 

after that I have a error to use pip3 install other library, the console print:

File "/usr/bin/pip3", line 11, in <module>
    sys.exit(main())
TypeError: 'module' object is not callable

I don't know what I have to do.

I use sudo autoremove python3-pip after that I use sudo apt install python3-pip

blackbrandt
  • 2,010
  • 1
  • 15
  • 32
  • maybe it imports some of your file instead expected module and it has problem to run it - it can be ie. `main.py`. Did you try to use `pip` in different folder ? – furas Oct 15 '19 at 04:00
  • 1
    I also had the same error. – Hyrial Oct 15 '19 at 06:25
  • Thanks for getting me started - I listed my procedure for fixing this on https://stackoverflow.com/questions/34573159/how-to-install-pip3-on-my-mac/59245705#59245705 – jvonehr Dec 09 '19 at 09:16

5 Answers5

66

From the link by Bram, I just ran python3 -m pip uninstall pip, and it started to work again.

Hyrial
  • 1,728
  • 3
  • 15
  • 27
  • 5
    Can somebody explain this? – Saif Nov 08 '19 at 00:13
  • 6
    @SaifUrRahman: From the provided link it seems that this is a conflict between a user specific pip installation (which gets installed/upgraded by the OPs command) and the global pip installation provided by the operating system. – vlz Dec 11 '19 at 13:55
  • for some reason, I get a giant error starting with 'Could not install packages due to an EnvironmentError:" when I run `pip install pandas` for example. what could that be about? using the command @Hyrial suggested did help me install pandas with pip3, when before i got the same "module not callable" error. – alpablo20 Dec 15 '21 at 04:27
6

The solution which worked for my situation is simply editing the pip3.8 file in the ubuntu environment.

Method1:

#!/path/to/.venv/bin/python3
# -*- coding: utf-8 -*-
import re
import sys

from pip._internal.main import main  # <--- look at this import statement! 

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

method2:

The main function has to be imported or we can simply replace line

sys.exit(main())

As

sys.exit(main.main())
i_am_deesh
  • 448
  • 3
  • 12
  • Thanks! method #2 worked for me. I'm nervous about it, because I'm afraid it will fail the next time I update /Applications/Xcode.app/Contents/Developer/usr/bin/pip3. – Jetpack Dec 30 '19 at 23:29
6

Use this

python -m pip install --upgrade --user [name_of_your_package]

Purushottam
  • 844
  • 14
  • 25
4

As seen here, you should be able to solve this by running the module from Python directly, i.e.

python -m pip install --upgrade pip
Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
1

In Windows edit C:\ProgramData\Anaconda3\Scripts\pip-script.py and replace

# -*- coding: utf-8 -*-
import re
import sys
from pip._internal import main

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

Replace the last line with sys.exit(main.main()).

Swaroop Maddu
  • 4,289
  • 2
  • 26
  • 38