Python pip installation in ubuntu - python

I am new to Ubuntu and was trying to install pip using get-pip.py , when I received this message.
Requirement already up-to-date: pip in /usr/local/lib/python2.7/dist- packages/pip-8.1.2-py2.7.egg
But when I enter pip -V, I receive an error saying :
The 'pip==7.1.0' distribution was not found and is required by the application
Complete error
I was trying to install new packages using pip install <packagename> but this command gives the same error as previous .

I suggest installing pip using the package manager. Open up a terminal and enter
sudo apt-get install python-pip
That should install the pip ubunutu package.

You should not be installing pip for the default python installation, neither from the package manager nor using get-pip.py. So you can never use it to break the system python.
Instead always use virtualenv (created from the default/system python or from a newer version), activate and use pip in that environment.

Related

Macos uninstall pip and start over

I'm new to macos and trying to get a dev environment going...I need pip but getting an error message with just pip.
Getting error pkg_resources.DistributionNotFound: The 'pip==20.0.2' distribution was not found and is required by the application
Python3 was installed with macos and I tried to install 2.x version and made it the global default. I think that's why I'm getting the above error.
I uninstalled the 2.x python using pyenv.
How can I remove pip (i've got pip, pip3 and pip 3.8) and start over.
Thanks.
Can you try removing pip using this in the directory where pip pacakge is installed?
sudo rm -r pip <Version Number>
You can get the directory where pip is installed with this: which pip and then cd into that path and run the above command.

What has happened to python-serial?

I have had replace an old PI2B, Jessie, Python 2.7, which satisfactorily ran some python code, with PI3B, Buster, Python 3.7, but I now cannot find/load python-serial. 'sudo apt-get install python-serial' installs it but when my python code is run it reports it as missing and 'sudo pip install python-serial' can't install it and comes back with the error below. Has it been replaced/superseded? What can I do to enable 'import serial' to work? Thanks
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting python-serial
Could not install packages due to an EnvironmentError: 404 Client Error: Not Found for url: https://pypi.org/simple/python-serial/"
Blockquote
Python 2's python-serial is Python 3's python3-serial (note the python3) It can be installed from buster repositories as of this post.
It can also be installed from pip here:
pip3 install pyserial
If pip is not available on the machine then it can be installed from source:
https://github.com/pyserial/pyserial/releases
Download the archive, extract it and install it with:
python setup.py install

Pip doesn't require root user to install but requires root user to upgrade

I'm confused by the intended pip usage. Pip comes installed with Python, which is great, but I get the following warnings when new versions come out:
WARNING: You are using pip version 21.1.1; however, version 21.1.3 is available.
You should consider upgrading via the '/usr/local/opt/python#3.8/bin/python3.8 -m pip install --upgrade pip' command.
I follow the instructions to install it using the command they gave. But then it uninstalls my existing pip and is not able to install the new version.
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.1.1
Uninstalling pip-21.1.1:
ERROR: Could not install packages due to an OSError: Cannot move the non-empty directory '/usr/local/lib/python3.8/site-packages/pip-21.1.1.dist-info/': Lacking write permission to '/usr/local/lib/python3.8/site-packages/pip-21.1.1.dist-info/'.
The pip command is now unrecognized, and the official documentation for upgrading pip suggests running:
python -m pip install -U pip
which gives the same permission error.
I Google this error, and found that the community highly advises to not sudo from these questions (this and this). They also advised pip3 install --upgrade pip --user which also gave the same error. The common consensus is to only install pip packages inside virtual environments, but I'm hesitant to have pip completely uninstalled.
So I got pip to install using sudo, but it's unclear whether I've inadvertently affected (or will affect future) system-wide installations, or how I'd check for these.
I don't understand why installing pip inside /usr/local/ requires sudo, and whether I should only be using pip exclusively inside virtual environments and never outside it
pip can be installed with sudo, into a folder that you don't have permissions to write to. However, it can install packages outside of that folder (and thus, into a folder you have write permissions). However, it is recommended that you don't install pip into a root folder, and instead install it into your home directory.
The command to install pip as root is
sudo apt-get install pip
It should then prompt you for your password. I recommend using sudo whenever you install something.

Why do I get an error "[Errno 42] Illegal byte sequence" when trying to install pillow using pip?

I want to install pillow, but when I run pip install pillow in the cmd I get the following message:
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting pillow
Downloading https://files.pythonhosted.org/packages/5e/b6/8960697526a79bd1cb4520293078be3a10d725f23f20abbee298ebdeaabd/Pillow-6.2.2-cp27-cp27m-win_amd64.whl (1.9MB)
|ERROR: Could not install packages due to an EnvironmentError: [Errno 42] Illegal byte sequence
WARNING: You are using pip version 19.2.3, however version 20.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Python 3.8.2 is already installed on my computer and I added it to PATH.
I also ran python -m pip install --upgrade pip and nothing has changed.
What is the problem? Do I need to update the Python version?
Installation using third party PPA repository
Step 1: First install the Ubuntu software properties package if it’s not already installed on your system.
$ sudo apt update
$ sudo apt install software-properties-common
Step 2: After that run the commands to add the PPA.
$ sudo add-apt-repository ppa:deadsnakes/ppa
Step 3: Finally, run below to install Python 3.8
$ sudo apt update
$ sudo apt install python3.8
You can check as below:
$ python3 --version
Python 3.8.1
OK done.
Don't use the pip, pip3, etc. scripts ever. Instead always prefer the more explicit and surefire way of calling pip's executable module for a specific instance of the Python interpreter, for example:
path/to/pythonX.Y -m pip install Pillow
References:
https://snarky.ca/why-you-should-use-python-m-pip/
https://snarky.ca/a-quick-and-dirty-guide-on-how-to-install-packages-for-python/
Check if Python3 is correctly installed by, for example, running python3 -V in the command-line (this will show you the installed version)
This should show something like Python 3.8 ...
If you get an error here, like it is an unknown command, something probably went wrong during the installation...
Run pip3 install pillow to install pillow (Python 3)
Kindly download it at Python official website.
There is an option to update your version during the installation which is very useful.

pip freeze gives different version from pip --version

I am on Windows 10 and just installed Python 3.7.4. I installed virtualenv using pip install virtualenv, and i got the message that i installed 16.7.2 while 19.2.1 is available. I then used python -m pip install --upgrade pip to upgrade.
Here is the issue: when i type pip freeze on Powershell, i am getting this:
virtualenv==16.7.2
but when i type pip --version, i am getting this:
pip 19.2.1 from c:\users\user1\python\lib\site-packages\pip (python 3.7)
Can you please let me know why pip freeze still shows the old version?
Thanks.
pip and virtualenv are 2 different cases where pip is mainly used for installing python packages and virtualenv for utilizing virtual environments while development.
The following command updates only pip not virtual env
python -m pip install --upgrade pip
If you think you still need to upgrade virtualenv (of course if a new version is available). Please follow the following syntax without specifying a version.
pip install [package] --upgrade

Categories

Resources