ImportError: No module named pip after trying to upgrade pip - python

I am using a MacOS 10.15 and Python version 3.7.7
I wanted to upgrade pip so I ran pip install --upgrade pip, but it turns out my pip was gone (it shows ImportError: No module named pip when I want to use pip install ...)
I tried several methods like python3 -m ensurepip, but it returns
Looking in links: /var/folders/sc/f0txnv0j71l2mvss7psclh_h0000gn/T/tmpchwk90o3
Requirement already satisfied: setuptools in ./anaconda3/lib/python3.7/site-packages (49.6.0.post20200814)
Requirement already satisfied: pip in ./anaconda3/lib/python3.7/site-packages (20.2.2)
and pip install still does not work and returns the same error message.
I also tried easy_install pip and other methods but pip still does not work.
Can anyone help me with this?
Update:
Using the method from #cshelly, it works on my computer!

Try the following:
python3 -m pip --upgrade pip
The -m flag will run a library module as a script.

The pip used by python3 is called pip3. Since you're using python3, you want to do pip3 install --upgrade pip.

Since it says no module named pip, thus pip is not installed in your system
So you may try
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
to download pip directly then you can use execute it using -
python3 get-pip.py
For details you may refer - https://www.geeksforgeeks.org/how-to-install-pip-in-macos/
PS: You may need to use sudo to make use of administrative privileges.

Related

How do I upgrade from pip 1.0?

I was trying to install a package which required an older version of pip and (stupidly) thought it would be a good idea to try installing the oldest version of pip possible (1.0).
To clarify, it is not pip 1.0.1 (which most guides I found on the internet refer to), but pip 1.0
When I attempt to run 'python -m pip install --upgrade pip', I get the following error:
C:\mydirectory\venv\Scripts\python.exe: No module named pip.__main__; 'pip' is a package and cannot be directly executed
When I run 'pip --version', I get the following info:
pip 1.0 from c:\mydirectory\venv\lib\site-packages (python 3.7)
Is there any way I can upgrade pip from this point?
python -m pip install -U pip should work. That is how I do it.
Try this:
python3 -m pip install pip

Install futures for python2

I have various versions of Python on my Ubuntu OS.
When I want to install futures, it writes the following message:
$ sudo pip2 install futures
Requirement already satisfied: futures in /usr/local/lib/python3.8/dist-packages (3.1.1)
When uninstall it and install it again, it does not help.
How would you install futures for Python2?
All the pips that I have (pip, pip2, pip2.7, pip3, pip3.6, pip3.7, pip3.8) point here:
pip 20.2.3 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
Can I change it?
Running pip install something may do what you expect if everything is configured well, but in general it often happens that you do not really know in which python that is going to install something.
To be certain in which python you are installing, it is best to run python -m pip instead of just pip. That way you can choose exactly which python installation should be updated, by simply using the same Python you would use to run later when you use the installed library e.g.:
python -m pip install something
or
python3 -m pip install something
or
/usr/bin/python2.7 -m pip install something
or
"C:\Program Files\Python3.6\python.exe" -m pip install something
or ...

Unable to install Requests module in python2.7 (Kali linux) as it keeps appearing in python3 library

I am using kali linux and is trying to import a module called requests to run an exploit. (https://www.exploit-db.com/exploits/47138) if you want to know more about the exploit.
when i try to run the following command
sudo pip install requests
i kept getting this result
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (2.23.0)
this cant work at all as i requires the Requests module to be in python2.
How can i get it installed?
pip install <package> -t <directory>
-t specifies the target directory where you want your package to be installed
So in your case you can do pip install requests -t "C:\Python27\Lib\site-packages" (This is where my site-packages folder is.)
You should use this command, it will ensure you are installing the module for python2:
python2 -m pip install --user --upgrade requests
You could use the following command:
sudo pip2.7 install requests
(Assuming that you have Python 2.7. If you have a different version, swap out the version number)

AttributeError: Module Pip has no attribute 'main'

I am trying to build the python api for an open source project called Zulip and I keep running into the same issue as indicated by the screenshot below.
I am running python3 and my pip version is 10.0.0. The file in question is setup.py and the code that is messing up is when the pip.main() attribute is accessed to install a package.
Now, I know this build should succeed because its an open source project, but I have been trying for hours to fix the dependency issue regarding pip.main().
Any help would be greatly appreciated.
python3 -m pip install --user --upgrade pip==9.0.3
pip issue: rollback
It appears that pip did a refactor and moved main to internal. There is a comprehensive discussion about it here: https://github.com/pypa/pip/issues/5240
A workaround for me was to change
import pip
pip.main(...)
to
from pip._internal import main
main(...)
I recommend reading through the discussion, I'm not sure this is the best approach, but it worked for my purposes.
First run
import pip
pip.__version__
If the result is '10.0.0', then it means that you installed pip successfully
since pip 10.0.0 doesn't support pip.main() any more, you may find this helpful
https://pip.pypa.io/en/latest/user_guide/#using-pip-from-your-program
Use something like
import subprocess
subprocess.check_call(["python", '-m', 'pip', 'install', 'pkg']) # install pkg
subprocess.check_call(["python", '-m', 'pip', 'install',"--upgrade", 'pkg']) # upgrade pkg
pip 10.0.1 still doesn't support main
You can choose to DOWNGRADE your pip version via following command:
python -m pip install --upgrade pip==9.0.3
This helps me, https://pip.pypa.io/en/stable/installing/
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
If you are using python3 and not set it default. do this,
python3 get-pip.py
It works for me.
My solution is to check the version number of pip and use the import the correct main function correctly
import pip
if int(pip.__version__.split('.')[0])>9:
from pip._internal import main
else:
from pip import main
def install(package):
main(['install', package])
To verify whether is your pip installation problem, try using easy_install to install an earlier version of pip:
easy_install pip==9.0.1
If this succeed, pip should be working now. Then you can go ahead to install any other version of pip you want with:
pip install pip==10....
Or you can just stay with version 9.0.1, as your project requires version >= 9.0.
Try building your project again.
If python -m pip install --upgrade pip==9.0.3 doesn't work, and you're using Windows,
Navigate to this directory and move the pip folders elsewhere.
Close your IDE if you have it open.
Press 'Repair' on Python 3.
Your IDE should cease to detect pip packages and prompt you to install them. Install and keep the last stable pip version by blocking automatic updates.
Pip 10.0.* doesn't support main.
You have to downgrade to pip 9.0.3.
Try this command.
python -m pip install --user pip==9.0.1
It works well:
py -m pip install --user --upgrade pip==9.0.3
Edit file:
C:\Users\kpate\hw6\python-zulip-api\zulip_bots\setup.py in line 108
to
rcode = pip.main(['install', '-r', req_path, '--quiet'])
do
rcode = getattr(pip, '_main', pip.main)(['install', '-r', req_path, '--quiet'])ยด
Not sure about Windows. But for mac users, use this:
pip install --upgrade pip==9.0.3
I fixed this problem upgrading to latest version
sudo pip install --upgrade pip
My version:
pip 18.1 from /Library/Python/2.7/site-packages/pip (python 2.7)
I faced the same error while using pip on anaconda3 4.4.0 (python 3.6) on windows.
I fixed the problem by the following command:
easy_install pip==18.* ### installing the latest version pip
Or if lower version pip required, mention the same in the command.
Or you can try installing the lower version and then upgrading the same to latest version as follow:
easy_install pip==9.0.1
easy_install --upgrade pip
For me this issue occured when I was running python while within my site-packages folder. If I ran it anywhere else, it was no longer an issue.

pip is a package and cannot be directly executed

Im trying to install google assistant on my Raspberry Pi, but when I keep getting an error: pip is a package and cannot be directly executed
Instead of
pip [...]
Try doing
python -m pip [...]
Can't really help more without more info.
I think your version of pip is old. You need to upgrade it first, like this:
pip install -U pip
You may need to upgrade setuptools too:
pip install -U setuptools
Since google-assistant-library is available as a wheel, you need to install wheel too:
pip install wheel
I don't know if you can do that with Raspberry Pi, but I recommend you to used a virtualenv. That way, you have a fresh and isolated Python executable and a recent version of pip.
virtualenv your_proj
source your_proj/bin/activate
pip install wheel
pip install google-assistant-library
For newer version ie. using pip3:
pip3 install -U <<package name>>
I had the same problem.
I think it was an outcome of a failed
> .\python.exe -m pip install --upgrade pip
do to some environment misconfiguration.
So it first removed the existing version 10.0.1, and then the installation of the new version 22.3.1 failed, leaving me with no pip.
From official documentation, I ran
> .\python.exe -m ensurepip --upgrade
which restored the original pip 10.0.1.
Then I fixed the environment problem, and then again
> .\python.exe -m pip install --upgrade pip
I now have pip 22.3.1.

Categories

Resources