problem about pip on installing on python - python

when i want to install something on python like pip3 it doesn't work
when i write:
pip install (example)
or
pip3.exe
it says:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Python311\Scripts\pip3.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'
so what i gonna do?
i have been installed python3.11 again when i get this error but still doesn't work..

Check if python is added to environmental variables. If add the installation path to the environmental variables.
For me, the convenient way to uninstall and reinstall and check all the option which says add path to environmental variables.

Download the latest stable version of Python, make sure "install PIP" module is checked when running the setup of downloaded python on python.org/downloads/.
Then type py -m pip --version, to check if installed.
Hope this helps

Sometimes, pip isn't automatically bundled with python, you have to install it yourself.
You can run: python -m ensurepip --upgrade to install pip.
Then, you can run: python -m pip install x to install module x.
To upgrade pip, run: python -m pip install --upgrade pip.
If you want, the pip documentation here lists a few other ways of doing this.

Related

Pip command line "ImportError: No Module Named Typing"

Running the following command gives me the following error:
pip install pygame
Error Stack:
Traceback (most recent call last):
File "C:\Python34\lib\runpy.py", line 171, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python34\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Python34\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Python34\lib\site-packages\pip\__init__.py", line 1, in <module>
from typing import List, Optional
ImportError: No module named 'typing'
Running this line in a Mac terminal fixed it for me:
/usr/local/opt/python#3.9/bin/python3.9 -m pip install --upgrade pip
I had the same issue. I also first tried the pip3 install pygame which was previously mentioned, before running this line. You may have to do that first. For the individual who said to try
pip install typing
that line of code will simply produce the same error. To fix it, you have to use to the aforementioned command(s).
I also ran into the same problem, because I made the foolish mistake of upgrading pip as suggested by Python.
I fixed this by downloading get_pip.py for python3.4 at https://bootstrap.pypa.io/pip/3.4/get-pip.py and running it:
python get_pip.py
It will automatically download the latest compatible version of pip (19.1.1 in this case).
Try to:
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python get-pip.py
Do the following:
sudo apt update
sudo apt-get upgrade
If there is a problem, do:
sudo apt --fix-broken install
sudo apt-get upgrade
If there is still a problem, remove and recreate your venv. And Reinstall your requirements:
rm -rf venv
python3.9 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
I encountered the same error on Ubuntu 20.04 when using python3.9, I tried to run sudo apt update && sudo apt upgrade.
The output advised me to run sudo apt --fix-broken install, which had solved my problem and python3.9 is running fine now.
I have also met this problem. Any command that starts with pip have the same error, ImportError: No module named 'typing'.
Finally, python -m pip install typing solved it.
I had this error using pip because my Ubuntu installation with Python 2.7 and Python 3.5 were crossed using the versions and pip.
My solution was to uninstall Python 2.7 and pip 2.7. I also uninstalled Python 3.5 and pip 3.
I then installed Python 3.7 using these directions: Installing the latest Python 3.7 on Ubuntu 16.04 and 18.04
I'm not sure if uninstalling 3.5 and adding 3.7 is necessary. You may just be able to remove 2.7 and be good, but this is what worked for me.
Try this one:
pip3 install pygame
It looks like you are importing from the package 'typing' but you do not have it installed. Try installing the package:
pip install typing

Python no module named pip

I use windows 7 32 bit and python 3.7.
I was trying to install a module with pip and this error came up:
C:\Windows\System32>pip install pyttsx3
Traceback (most recent call last):
File "d:\python\python 3.7\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\python\python 3.7\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\Python\Python 3.7\Scripts\pip.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'
Does anybody know how to fix this?
Make sure you have python path added to the PATH variable. Then run
python -m ensurepip
Could you try?
pip3 install pyttsx3
To me for Ubuntu 20.04 helped the following:
ls -al /usr/bin/python # check before removal that 'python' is link
sudo rm /usr/bin/python # remove link to old version of python
sudo ln -s /usr/bin/python3.8 /usr/bin/python # create new link to actual python version
sudo apt install python3-pip # install missing pip
"Python: No module named pip" was because of missing python3-pip.
Start Python Setup again (Download from here) and be sure to tick that Add python to PATH at the bottom of installation.
Download get-pip.py to a folder on your computer.
Open a command prompt and navigate to the folder containing the
get-pip.py installer.
Run the following command:
python get-pip.py
4-) Verify Installation and Check the Pip Version:
pip -V
This command finally worked for me
python -m pip install --upgrade pip --trusted-host pypi.org --trusted-host files.pythonhosted.org

ModuleNotFoundError: No module named 'pip' python3 [duplicate]

This question already has answers here:
ImportError: No module named pip
(31 answers)
Closed 10 months ago.
I can't use pip and I don't know why.
The error I get is shown below:
File "d:\python\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "d:\python\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "D:\Python\Scripts\pip.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'
If I try py -3.8 -m pip install I get
D:\Python\python.exe: No module named pip.
If I use get-pip nothing happens.
If I try to upgrade pip nothing happens.
Try
python -m ensurepip
This command activates pip.
Ref. https://docs.python.org/3/library/ensurepip.html
After this you can upgrade
python -m pip install --upgrade pip
I had the same problem. But in my case, when I was upgrading the pip version the new version stopped installing (upgrading) before the older version successfully uninstalled. After searching 4 or 5 sites I found:
python -m ensurepip
I was able to use the pip command and also this:
python -m pip install --upgrade pip
I don't know what OS you are using and what errors you got when using get-pip, but I had similar issue on Ubuntu20 and this solved it:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Credit: #Benjamin's answer here: https://askubuntu.com/questions/1025189/pip-is-not-working-importerror-no-module-named-pip-internal
For Debian/Ubuntu/Linux Mint and derivatives users
Install pip using APT:
sudo apt install python3-pip
Try this
python -m pip install --upgrade pip
A suggestion, try to use anaconda or virtual env to avoid such issues.
I had the same problem, but found that python -m ensurepip just told me that the pip scripts were already installed. So what I did was delete the 2 pip directories under C:\Users\[user_id]\AppData\Local\Programs\Python\Python38\Lib\site-packages, then run python -m ensurepip again. That fixed it for me.

pip3 error - '_NamespacePath' object has no attribute 'sort'

I tried to install a package through pip3, and I got this error. Every pip/pip3 command that I run gives me this error-
alexg#hitbox:~$ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip import main
File "/home/alexg/.local/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/alexg/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 27, in <module>
from pip._vendor import pkg_resources
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
#_call_aside
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
f(*args, **kwargs)
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
dist.activate(replace=False)
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
declare_namespace(pkg)
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
_handle_ns(packageName, path_item)
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
_rebuild_mod_path(path, packageName, module)
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2121, in _rebuild_mod_path
orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'
I have tried running pip3 install --upgrade pip setuptools according to some answers, but every pip command gives me the error. I'm stuck and can't do anything.
What could have caused it, and how can this be fixed?
I'm on Ubuntu 16.04 with Python 3.5.2
I met the same issue with python 3.5.2 and pip3 (9.0.1). And I fixed it by following this workaround: https://github.com/pypa/setuptools/issues/885#issuecomment-307696027
More specifically, I edited line #2121~2122 of this file: "sudo vim /usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py"
#orig_path.sort(key=position_in_sys_path)
#module.__path__[:] = [_normalize_cached(p) for p in orig_path]
orig_path_t = list(orig_path)
orig_path_t.sort(key=position_in_sys_path)
module.__path__[:] = [_normalize_cached(p) for p in orig_path_t]
Upgrading setuptools worked for me:
pip3 install --upgrade setuptools
This may sound weird, because I had this issue and I had tried everything mentioned in SO and GitHub issues. But then I installed pip with easyinstall and pip command is working. Maybe now there are 2 pip packages now. But error is gone.
easy_install pip
I'm using virtualenv and upgrading setuptools didn't work for me. What did work was this workaround:
pip uninstall setuptools -y && pip install setuptools
Yet another answer, but following is the one which eventually fixed the issue for me. Since pip was compromised I was unable to use it for upgrading itself or setuptools and also using easy_install was bringing up the same issue. So I tried to install pip using Python.
The answer:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
pip install --upgrade setuptools
try -
pip install -U pip
pip install -U setuptools
if editing __init__.py doesnt help.
I tried most of the above suggested solutions but nothing worked as pip3 was totally non-functional, then I found this:
https://deeptalk.lambdalabs.com/t/trying-to-uninstall-tensorflow-or-matplotlib-pip-package-throws-attributeerror--namespacepath-object-has-no-attribute-sort/310
I think this is probably the issue with most of us. I tried the suggested solution and pip3 is working again.
For me the matplotlib was not present in dist-packages but instead it was in site-packages, so the command that worked for me was:
sudo rm ~/.local/lib/python3.5/site-packages/matplotlib-3.0.3-py3.5-nspkg.pth
ofcourse you need to change the above path based on your version and location of matplotlib.
This probably means that your dependencies got messed up.
Try to uninstall pip3 from scratch and it should work.
In case it doesn't work, delete your pip installation. In your case:
rm -r /home/alexg/.local/lib/python3.5/site-packages/pip/
And to be sure next time, best to work with virtual environments :)
Try :
sudo easy_install pip
and then
sudo easy_install setuptools
It probably happends because of messed-up dependencies.
I had the same problem using poetry.
Running
poetry run pip install --upgrade pip setuptools
instead of
pip install --upgrade pip setuptools
fixed the issue.
I had this same problem, and was unable to run any command with pip3 (including any commands like pip3 install --upgrade pip setuptools).
Only fix I've found was to completely uninstall and re-install python 3 (sudo apt-get remove python3, sudo apt-get install python3, sudo apt install python3-pip) and now pip3 is working properly again.
After trying all kinds of methods, such as reinstall pip, setuptools, and still can't fix the problem.
I follow the instruction of https://github.com/pypa/pip/issues/4216#issuecomment-286348680 and only with an external warning.
After that, I use pip to uninstall matplotlib.
Finally, all things seem okay.
I had this problem consistently (and used the workaround below to use pip in the python3 interpreter). To my surprise, after uninstalling all versions of numpy and reinstalling the latest one, pip began working again. I can't say for sure what happened, but it might be something to try if everything else has failed.
The workaround (pieced together from several sources I don't recall) is
start python3
import pip twice (getting an error the first time)
use pip.main within the interpreter
Here is a transcript:
>>> import pip
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py",
__import__(vendored_name, globals(), locals(), level=0)
ImportError: No module named 'pip._vendor.pkg_resources'
During handling of the above exception, another exception occurred
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 13,
from pip.exceptions import InstallationError, CommandError, Pi
File "/usr/lib/python3/dist-packages/pip/exceptions.py", line 6,
from pip._vendor.six import iteritems
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", l
vendored("pkg_resources")
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", l
__import__(modulename, globals(), locals(), level=0)
.
etc
.
AttributeError: '_NamespacePath' object has no attribute 'sort'
>>> import pip
>>> pkgs = ['asciiplotlib']
>>> pip.main(['install'] + pkgs + ['--upgrade'])
Collecting asciiplotlib
Using cached https://files.pythonhosted.org/packages/15/c5/46a2d
Installing collected packages: asciiplotlib
Successfully installed asciiplotlib-0.1.8
I fixed this with follows:
$curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
For python2:
$python get-pip.py
For python3:
$python3 get-pip.py
Now it works for me.
None of the other posted answered worked for me, but running the follow command solved t:
sudo apt-get purge --auto-remove python3-pkg-resources python3-setuptools
This is for windows users, who installed WinPython
We couldn't even run pip command. Uninstall and install of Anaconda 3
We faced similar error. Finally we removed folder "Python" which is inside C:\Users\you\AppData\Roaming\ and removed folder "conda" & "packages" which is inside C:\Users\you\AppData\Roaming\conda.
Then it worked.

ImportError: No module named extern

I'm getting this error when trying to install any package with pip. I have two pip instances, one with Python 2.7 and other with Python 3.
Could not import setuptools which is required to install from a source distribution.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 375, in setup_py
import setuptools # noqa
File "/usr/local/lib/python2.7/dist-packages/setuptools/__init__.py", line 11, in <module>
from setuptools.extern.six.moves import filterfalse, map
File "/usr/local/lib/python2.7/dist-packages/setuptools/extern/__init__.py", line 1, in <module>
from pkg_resources.extern import VendorImporter
ImportError: No module named extern
Even when I try to install the 'extern' module I get this error. Also when installing with Python itself, like python setup.py install.
Thanks in advance.
sudo apt-get purge python-pkg-resources
sudo apt-get -f install
here actually packages are removed and
purged (any configuration files are deleted too).
-f : Attempt to correct a system with broken dependencies in place.
sudo pip install packagename
#sourcehere
Do this it will work
sudo pip install -U setuptools
I know this is an old thread, but I just wanted to contribute since I ran into this issue and this thread kept coming up in the results.
Note: This was on MacOS 10.12. My shell is zsh and I already have brew installed
First I ran each of these commands
brew install python
brew install python3
This will either install it or you'll receive an "already installed" message as I did.
Next, run the following command
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
And last:
sudo python get-pip.py
Final note: for my install to work, I ended up having to run the command with pip3
sudo pip3 install nameofinstallhere
Not sure whether it is installation issue or packege but it seems like you will not be able to import any package of them, if you have installed python perfectly then
try this commands
step 1 :
$which pip
/usr/local/bin/pip
step 2 :
/usr/local/bin/pip install django
or any of your package name.
I am considering ubuntu(OS)
You can try the following command; it has worked for me:
sudo apt-get install --reinstall python-setuptools

Categories

Resources