Pip is not working for Python 3.10 on Ubuntu - python

I am new to using Ubuntu and Linux in general. I just attempted to update Python by using sudo apt-get install python3.10. When I run python3.10 -m pip install <library name> I always receive the following error:
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
sys.exit(_main())
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand
File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 15, in <module>
from pip._internal.index.package_finder import PackageFinder
File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21, in <module>
from pip._internal.index.collector import parse_links
File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
from pip._vendor import html5lib, requests
ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)```
I have tried doing sudo apt-get install python3.10-html5lib it downloaded something but it did not fix the error. How should I fix this error?

This is likely caused by a too old system pip version.
Install the latest with:
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
and test result
python3.10 -m pip --version
e.g.
pip 22.2.2 from <home>/.local/lib/python3.10/site-packages/pip (python 3.10)
and then test upgrade
python3.10 -m pip install --upgrade pip
e.g.
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in <home>/.local/lib/python3.10/site-packages (22.2.2)

I have tried all the answers above but nothing worked for me. My python3 version is 3.10.2.
So I need to install the appropriate version for pip.
However, I have tried
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
But didn't work so, I tried
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
This worked for me

This is an expanded version of #mirekphd's comment which gave me a solution that worked both on my laptop and on our server perfectly without messing anything up.
First step, if not already done is to add the 'deadsnakes' repository so that the latest python related software can be downloaded and kept updated.
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa
And, if you don't have Python 3.10 already installed you can do that with:
sudo apt install python3.10
And finally, to make pip work you will need to install the distutils package that's compatible with 3.10:
apt install python3.10-distutils
After that you can use pip the following way:
python3.10 -m pip _rest_of_the_pip
The above is necessary because the regular pip command will utilize the systems default python version and not 3.10.
If you use pip frequently then you can add an alias to your .bashrc file such as:
alias pip310='python3.10 -m pip'
After that you can just use it like this:
pip310 install blah

I've had this problem inside GitHub Actions. My solution was to resort to virtual environments to isolate from the rest of the system. Ensure python3.10-venv is installed and then do
python3.10 -m venv .venv
source .venv/bin/activate
pip install ...
...
deactivate

I had some issues installing pip as well
As sudo apt install python3-pip is still refering to pip3.8 (on mint Cinnamon 20.2 at least), pip needs to be installed in a other way.
With curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10, it turns out that pip is not found
ImportError: No module named 'pip._internal'
I found out that ensurepip command was built in and target the correct directory for python3.10
Running python3.10 -m ensurepip installs setuptools and pip and fix my missing pip module.
Pip can be updgraded afterwards using python3.10 -m pip install -U pip.
It also work with sudo (had some needs running pip as sudo)

At the time of writing and as stated on the following link. Python 3.10 is still unstable. Maybe it is a good idea to test what happens with python3.9 and see if the issue is in your local installation.
in any case, from a clean ubuntu (docker) installation by running (with sudo rights)
apt-get install software-properties-common
apt-get install python3.9
python3.9 --version
#
apt-get install python3.10
python3.10 --version
I got an the answers Python 3.9.5 and bash: python3.10: command not found respectively. so I guess the issue could be in the python 3.10 repository... for now.
However, apt-get install will not update directly your "default" python. You can check which are your those installations with
python --version
python3 --version
Any way, if you still want to install python3.10, perhaps the link above could help you.

Try:
pip3.10 install <package name>
Make sure you have the latest version pip and python3.10

The code for installing python and pip 3.10 for Ubuntu is all there, it's enough to swap just one line of that code, changing base image to the latest Ubuntu LTS version (that's ubuntu:focal) in the Dockerfile for the official Debian-based python 3.10 image (I used python 3.10 bullseye slim Dockerfile. Docker build took just 8 minutes, and here is proof that pip3.10 really works there:
$ docker run mirekphd/python3.10-ubuntu20.04 pip -V
Output:
pip 21.3.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
Or a more advanced example:
$ docker run -it --rm --name python3.10-ubuntu20.04 mirekphd/python3.10-ubuntu20.04:latest bash -c 'pip --version; pip install numpy --user --no-cache; pip show numpy; python -c "import numpy as np; print(np.ones(5))"'
Output:
pip 21.3.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
Collecting numpy
Downloading numpy-1.21.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.9 MB)
|████████████████████████████████| 15.9 MB 34.6 MB/s
Installing collected packages: numpy
WARNING: The scripts f2py, f2py3 and f2py3.10 are installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed numpy-1.21.4
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Name: numpy
Version: 1.21.4
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email:
License: BSD
Location: /root/.local/lib/python3.10/site-packages
Requires:
Required-by:
[1. 1. 1. 1. 1.]
Note: to upgrade pip, I just added this line (before CMD):
RUN python -m pip install --upgrade pip

I've got the same error after installing python 3.10 on Ubuntu with python 3.8 on board.
uninstall pip and install it again
sudo apt-get remove -y python3-pip
sudo apt-get install -y python3-pip
it's worked for me, but pip3.10 install modulename got the same error, and python3.10 -m pip install modulename working fine.

in my case this problem is associated to a previous conda installation... so I solve it by correcting the PATH. Since also Python3.10 & pip3 are installed in ~/.local/bin
In the worst way, I added a last line to ~/.bashrc hardcoded as follows
nano ~/.bashrc
add the last line:
export PATH=/usr/local/sbin:/sbin:/usr/sbin:/root/bin:/usr/local/bin:/usr/bin:/usr/local/games:/usr/games:/home/$USER/.local/bin
save, close and run
source .bashrc
this was not enough, because after removing Conda's paths it still left pip installed in /usr/bin I solved this by renaming this pip
cd /usr/bin
sudo mv pip kkpip
sudo mv pip3 kkpip3
done
pip3 list
Voilà!

Install python 3.10, pip and venv in Ubuntu 18|20
sudo apt update && sudo apt upgrade -y
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10
python3.10 --version
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
python3.10 -m pip --version
python3.10 -m pip install --upgrade pip
sudo apt install python3.10-venv
Create a virtual environment,
python3.10 -m venv venv3.10
source venv3.10/bin/activate

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

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

Pip: ImportError: Entry point ('console_scripts', 'pip') not found

I install pip with:
$ sudo apt-get install python-setuptools, python-pip
But when I try install something with pip i have this error
sudo pip install Flask
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==1.3.1', 'console_scripts', 'pip')()
File "/usr/local/lib/python2.7/dist-packages/pkg_resources.py", line 378, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources.py", line 2565, in load_entry_point
raise ImportError("Entry point %r not found" % ((group,name),))
ImportError: Entry point ('console_scripts', 'pip') not found
why?? Thanks.
sudo python3 -m pip install --upgrade --force-reinstall pip
may do the trick. Try it
I remove setuptools 0.9.4 and do 'pip install --upgrade setuptools' and work good.
you may check the /usr/bin/pip file, if it links to pip2, then change the first line of pip2 from '/usr/bin/python' to '/usr/bin/python2.7' or '/usr/bin/python2.x' matching pip2. If it links to pip3, then change to python3 or the version python3.x matching pip3.
It works for me because I have installed python 2.7 and 3 so and pip. So when I use 'pip' it using python3 as default, which resulting in the same output.
I was facing almost same error and having python2.7 installed on my mac.
I tried sudo python2.7 -m pip install --upgrade --force-reinstall pip and it worked for me.
If you have python3 installed then you can try sudo python3 -m pip install --upgrade --force-reinstall pip
Hope it will work.
I find there are multiple version pip on my Ubuntu,I followed these steps and it worked:
sudo apt-get remove python-pip
sudo rm -rf /usr/local/bin/pip-2.7 sudo rm -rf /usr/local/bin/pip
sudo rm -rf /usr/local/lib/python2.7/dist-packages/pip-1.4.1.egg-info
sudo easy_install -m pip-2.7 sudo easy_install -m pip
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
sudo python get-pip.py

pip broke. how to fix DistributionNotFound error?

Whenever i try to use pip I get an error. For exampple:
$ sudo pip install gevent-websocket
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2675, in <module>
parse_requirements(__requires__), Environment()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 552, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==0.8.1
I feel tempted to change the value of into pip==0.8.2.. but I dont feel dealing with the consequences of 'hacking' up my installation...
I'm running python 2.7 and pip is at version 0.8.2.
I find this problem in my MacBook, the reason is because as #Stephan said, I use easy_install to install pip, and the mixture of both py package manage tools led to the pkg_resources.DistributionNotFound problem.
The resolve is:
easy_install --upgrade pip
Remember: just use one of the above tools to manage your Py packages.
I replaced 0.8.1 in 0.8.2 in /usr/local/bin/pip and everything worked again.
__requires__ = 'pip==0.8.2'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('pip==0.8.2', 'console_scripts', 'pip')()
)
I installed pip through easy_install which probably caused me this headache.
I think this is how you should do it nowadays..
$ sudo apt-get install python-pip python-dev build-essential
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv
I had this issue when I was using homebrew. Here is the solution from Issue #26900
python -m pip install --upgrade --force pip
Try re-installing with the get-pip script:
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
This is sourced from the pip Github page, and worked for me.
If you're on CentOS make sure you have the YUM package "python-setuptools" installed
yum install python-setuptools
Fixed it for me.
The root of the problem are often outdated scripts in the bin (Linux) or Scripts (Windows) subdirectory. I'll explain this using problem I encountered myself as an example.
I had virtualenv version 1.10 installed in my user site-packages (the fact it's in user site-packages not sytem site-packages is irrelevant here)
pdobrogost#host:~$ which virtualenv
/home/users/pdobrogost/.local/bin/virtualenv
pdobrogost#host:~$ virtualenv --version
1.10
After I upgraded it to version 1.11 I got the following error:
pdobrogost#host:~$ virtualenv --version
Traceback (most recent call last):
File "/home/users/pdobrogost/.local/bin/virtualenv", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2701, in <module>
return self.__dep_map
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 572, in resolve
if insert:
pkg_resources.DistributionNotFound: virtualenv==1.10
File /home/users/pdobrogost/.local/bin/virtualenv mentioned in the error message looked like this:
#!/opt/python/2.7.5/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'virtualenv==1.10','console_scripts','virtualenv'
__requires__ = 'virtualenv==1.10'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('virtualenv==1.10', 'console_scripts', 'virtualenv')()
)
There, we see that virtualenv script was not updated and still requires previously installed version 1.10 of virtualenv.
Now, reinstalling virtualenv like this
pdobrogost#host:~$ pip install --user --upgrade virtualenv
Downloading/unpacking virtualenv from https://pypi.python.org/packages/py27/v/virtualenv/virtualenv-1.11.1-py27-none-any.whl#md5=265770b61de41d34d2e9fdfddcdf034c
Using download cache from /home/users/pdobrogost/.pip_download_cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fpy27%2Fv%2Fvirtualenv%2Fvirtualenv-1.11.1-py27-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...
does not help (neither pip install --user --upgrade --force-reinstall virtualenv) because script /home/users/pdobrogost/.local/bin/virtualenv is left unchanged.
The only way I could fix this was by manually removing virtualenv* scripts from /home/users/pdobrogost/.local/bin/ folder and installing virtualenv again. After this, newly generated scripts refer to the proper version of the package:
pdobrogost#host:~$ virtualenv --version
1.11
I was able to resolve this like so:
$ brew update
$ brew doctor
$ brew uninstall python
$ brew install python --build-from-source # took ~5 mins
$ python --version # => Python 2.7.9
$ pip install --upgrade pip
I'm running w/ the following stuff (as of Jan 2, 2015):
OS X Yosemite
Version 10.10.1
$ brew -v
Homebrew 0.9.5
$ python --version
Python 2.7.9
$ ipython --version
2.2.0
$ pip --version
pip 6.0.3 from /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.3-py2.7.egg (python 2.7)
$ which pip
/usr/local/bin/pip
I was facing the similar problem in OSx. My stacktrace was saying
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: setuptools>=11.3
Then I did the following
sudo pip install --upgrade setuptools
This solved the problem for me. Hope someone will find this useful.
On Mac OS X (MBP), the following (taken from another answer found herein) resolved my issues:
C02L257NDV33:~ jjohnson$ brew install pip
Error: No available formula for pip
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can:
sudo easy_install pip
C02L257NDV33:~ jjohnson$ sudo easy_install pip
Clearly the root cause here is having a secondary method by which to install python (in my case Homebrew). Hopefully, the people responsible for the pip script can remedy this issue since its still relevant 2 years after first being reported on Stack Overflow.
I had this problem because I installed python/pip with a weird ~/.pydistutils.cfg that I didn't remember writing. Deleted it, reinstalled (with pybrew), and everything was fine.
In my case (sam problem, but other packages) there was no version dependency. A sequence of pip uninstall and pip insstall did help.

Categories

Resources