I installed python3 and pip3 successfully on my Ubuntu16.04, but pip3 install is broken. How can I fix this problem? The error info of pip3 install is as follows:
# pip3 install xlwt
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 21, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
ModuleNotFoundError: No module named 'pip._vendor.requests'
Output of "which pip3" and "pip3 --version":
# which pip3
/usr/bin/pip3
# pip3 --version
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 21, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
ModuleNotFoundError: No module named 'pip._vendor.requests'
p.s. Python2 pip runs successfully.
Output of "which pip" and "pip --version":
# which pip
/usr/bin/pip
# pip --version
pip 1.5.4 from /usr/local/lib/python2.7/dist-packages/pip-1.5.4-py2.7.egg (python 2.7)
And python and python3 installation information:
# which python
/usr/bin/python
# which python3
/usr/bin/python3
# python -V
Python 2.7.14
# python3 -V
Python 3.6.3
Any solution or clue will be appreciated! Thank you!
Here, trying this method: https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py
# sudo python3 get-pip.py
This has happened to me multiple times before. A lot of the time, pip3 has issues installing with python3 by default, so try uninstalling and reinstalling pip3. Hope this works.
sudo apt-get remove python3-pip; sudo apt-get install python3-pip
EDIT:
After doing some scouting about pip.vendor.requests, it seems like this is a very common error relating to SSL problems. If this line gives you errors in python (import ssl), some solutions can be found here:
https://github.com/pypa/pip/issues/2345.
This worked for me.
First remove your python3-pip:
sudo apt remove python3-pip
Then do this:
sudo apt install --purge python3-setuptools
And finally:
sudo apt install python3-pip
python-pip is in the universe repositories, therefore use the steps below to solve Python3 pip3 broken problem on Ubuntu. Also works for Ubuntu available from official store in windows 10 for WSL (windows subsystem for linux):
sudo apt-get install software-properties-common
sudo apt-add-repository universe
sudo apt-get update
sudo apt-get -y install python3-pip
I got help from here - [https://askubuntu.com/a/672836/876942]. Following these steps installs python 2. But then I installed python 3 using [sudo apt-get -y install python3-pip] in last step.
Related
I need to update the default python version in Google Colab to version 3.9 in order to install some packages via poetry. However, when I update python I seem to lose the ability to install anything at all. I'm updating python by following the accepted answer here, which works in so far as giving me the version of python I need:
#install python 3.9
!sudo apt-get update -y
!sudo apt-get install python3.9
#change alternatives
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
#check python version
!python --version
# returns Python 3.9.13
However, when I then try to install poetry via !pip3 install poetry I get the following response:
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
Curiously, when I try !pip3 install poetry before updating python it works. However, if I install poetry first, then update python, when I try to install the variopus packages I need via !poetry install I get a similar traceback error:
Traceback (most recent call last):
File "/usr/local/bin/poetry", line 5, in <module>
from poetry.console import main
ModuleNotFoundError: No module named 'poetry'
Long-story-short, I can't work out how I can get the version 3.9 of python in Colab AND poetry to work.
Yes you need to install pip with !sudo apt-get install python-pip
Then you might need the distutils lib !sudo apt install python3.9-distutils
I want to install Python 3.10 on Ubuntu 18.04 (I'm currently on Python 3.8) from the deadsnakes repository with the following set of commands I found on the internet:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.10
But I got the error sudo: add-apt-repository: command not found.
More net research led me to this set of commands at "ModuleNotFoundError: No module named 'apt_pkg'" appears in various commands - Ask Ubuntu:
sudo apt remove python3-apt
sudo apt autoremove
sudo apt autoclean
sudo apt install python3-apt
Other web sources said the same thing, so I did that, but I still get the error message when I run sudo add-apt-repository ppa:deadsnakes/ppa.
Then I found How to Fix 'add-apt-repository command not found' on Ubuntu & Debian - phoenixNAP, which advised this set of commands:
sudo apt update
sudo apt install software-properties-common
sudo apt update
so I did that, but when I run sudo add-apt-repository ppa:deadsnakes/ppa I now get this error message:
~$ sudo add-apt-repository ppa:deadsnakes/ppa
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 12, in <module>
from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 28, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
I have found some web links that show a wide variety of solutions with earlier versions of Python. I'm currently on Python 3.8.
Before I do anything more I want to ask what is the best way to solve the ModuleNotFoundError: No module named 'apt_pkg' error message when trying to install the deadsnakes repository to install Python 3.10, given the number of possible solutions I have seen.
Thanks very much.
This worked for me:
sudo apt-get install python3-apt --reinstall
cd /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so
The 38 in the filename above can be different for you.
I have installed python3.5 on my server. I installed pysher with pip3, everything works fine, in python3.5 terminal, I can use import pysher without error. Now, I develop script, where is some python3.6 features, so I installed python3.6 on my server and now, I am not able to import pysher in python3.6 terminal:
>>> import pysher
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pysher'
So I tried install pysher again:
# pip3 install pysher
The program 'pip3' is currently not installed. You can install it by typing:
apt install python3-pip
Even when I konw I have installed python3-pip, I tried it agian:
# apt install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pip is already the newest version (8.1.1-2ubuntu0.4).
0 upgraded, 0 newly installed, 0 to remove and 138 not upgraded.
Of course, I can rewrite my second script to work with python3.5, but I am curious why it is not working and how to repair it.
UPDATE 1:
dpkg -L python3-pip | grep bin
/usr/bin
/usr/bin/pip3
export PATH="$PATH:/usr/bin/pip3"
pip3 search pysher
The program 'pip3' is currently not installed. You can install it by typing:
apt install python3-pip
This did not work, so I try get version of pip3:
# /usr/bin/pip3 --version
-bash: /usr/bin/pip3: No such file or directory
pip3 is not in /usr/bin/.
Run dpkg -L python3-pip to find out where apt installed your pip3. Then
export PATH="$PATH:/usr/bin/mypippath
Will add it to your path. After that, trypip3 again.
There is two way to work with pip files.
1 - Inside of a program file like this :
import pip
pip.main(["install" , "package"])
2 - Getting into the scripts folder in Python directory and command line and printing the following content :
C:\Python\Python35\Scripts\pip.exe install package
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
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