Installing pip on macOS does not work (anymore) - python

I followed online instructions on how to install pip on macOS (for example this, this, and this).
I all seems to simple, but it's not working for me.
My python --version is 2.7.10.
When I run sudo easy_install pip I get:
$ sudo easy_install pip
Password:
Searching for pip
Reading http://pypi.python.org/simple/pip/
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')
Any idea how I can fix or work around this?

You might have pip3 instead. Use it to upgrade pip.
pip3 install --upgrade pip

Use brew for Macs
brew install python
this will come with pip and both python2 and python3
instructions to bypass 2 python versions (if you want) are at https://pip.readthedocs.io/en/stable/installing/
otherwise, it'll just be "python3 <'program'>"
Here's how to install brew:
https://www.howtogeek.com/211541/homebrew-for-os-x-easily-installs-desktop-apps-and-terminal-utilities/

easy_install has been deprecated. Use below commands instead.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Source

Related

Upgrading pip on mac

I'm trying to upgrade pip on my mac using this command
pip install --upgrade pip
After I enter that command I get this error
zsh: command not found: pip
I also can't even seem to get the version of pip when I enter this
pip --version
I get the same error.
I am new to this and I'm not sure what I'm doing wrong. It is possible the fact that I'm using zsh but honestly, I'm pretty sure I changed to zsh when installed homebrew but I forget what zsh even means for me.
Solution:
I solved my issue by using pip3 install --upgrade pip to upgrade to the latest version of pip. Now install using pip install works fine.
I'm not sure why I had to use pip3 but it works now.

Install opencv-python module

I'm trying to install the opencv module without success, I think the problem is related to the version of python I'm using.
Indeed I upgraded to the 3.9.1 version but when I'm trying to install the module, I still receive a warning referred to the old version of python I had (i.e. 2.7).
How can I get rid of this situation and successfully install the opencv library?
Error in bash
The issue is because the pip you are using in the insallation command conforms to pip2 which is used for installing packages for python2 (as is evident from the command output). You can verify the version by running:
pip --version
To solve the issue, use pip3:
sudo -H pip3 install opencv-python
If pip3 is not installed, install it via HomeBrew:
brew install python3
It should install pip3 as well. Also, have a look at this.

installing pycurl on osx 10.10 - don't know what to do with pycurl-7.10.5

I'm trying to install pycurl.
I downloaded and decompressed pycurl-7.10.5.tar.gz but I don't know what to do with the output.
Could someone help me with the install. I have python 3.5 and 3.3 installed as well as the Eclipse IDE with the PyDev extension.
I'd rather stay away from unix-like command line commands if possible and install from the native OSX interface. Something always goes wrong whenever I try things in the terminal.
For example, the first line of the INSTALL file tells me to
tar -zxvf pycurl-$VER.tar.gz
the response I get is:
tar: Error opening archive: Failed to open 'pycurl-.tar.gz'
Thank you,
Joe
The only real answer is to use a command line, one that you can run the python that you need to install curl to, i.e.:
pip install ./pycurl-7.10.5.tar.gz
if this fails try:
sudo pip install ./pycurl-7.10.5.tar.gz
in the directory that you downloaded the tar.gz to. BTW the terminal is the native interface. You will need to do this twice - once for each python.
You could always write a small python script to take the name of a package and do:
subprocess.call(['pip', 'install', name_of_package])
again you may need to run this with elevated privileges. (I don't have a Mac to try it out on). The good news is that if you are connected to the net at the time then just pip install pycurl should download the latest compatible version and install it all in one operation.
Missing pip?
If pip is missing then you can follow the installing pip instructions which consist of:
To install pip, securely download get-pip.py.
Then run the following (which may require administrator access):
python get-pip.py
If setuptools is not already installed, get-pip.py will install setuptools for you.
To upgrade an existing setuptools, run pip install -U setuptools.
Install behind a proxy:
python get-pip.py --proxy="[user:password#]proxy.server:port"
Upgrade pip
On Linux or OS X:
pip install -U pip
On Windows [5]:
python -m pip install -U pip
On OSX, you need to set the arch flag in the env. Try this, it should build:
sudo env ARCHFLAGS="-arch x86_64" pip3.5 install ./pycurl-7.43.0.tar.gz

Error with pip install lxml [duplicate]

I want to install Lxml so I can then install Scrapy.
When I updated my Mac today it wouldn't let me reinstall lxml, I get the following error:
In file included from src/lxml/lxml.etree.c:314:
/private/tmp/pip_build_root/lxml/src/lxml/includes/etree_defs.h:9:10: fatal error: 'libxml/xmlversion.h' file not found
#include "libxml/xmlversion.h"
^
1 error generated.
error: command 'cc' failed with exit status 1
I have tried using brew to install libxml2 and libxslt, both installed fine but I still cannot install lxml.
Last time I was installing I needed to enable the developer tools on Xcode but since it's updated to Xcode 5 it doesn't give me that option anymore.
Does anyone know what I need to do?
You should install or upgrade the commandline tool for Xcode.
Try this in a terminal:
xcode-select --install
I solved this issue on Yosemite by both installing and linking libxml2 and libxslt through brew:
brew install libxml2
brew install libxslt
brew link libxml2 --force
brew link libxslt --force
If you have solved the problem using this method but it pops up again at a later time, you might need to run this before the four lines above:
brew unlink libxml2
brew unlink libxslt
If you are having permission errors with Homebrew, especially on El Capitan, this is a helpful document. In essence, regardless of OS X version, try running:
sudo chown -R $(whoami):admin /usr/local
You may solve your problem by running this on the commandline:
STATIC_DEPS=true pip install lxml
It sure helped me.
Explanations on docs
I tried most of the solutions above, but none of them worked for me. I'm running Yosemite 10.10, the only solution that worked for me was to type this in the terminal:
sudo CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install lxml
EDIT: If you are using virtualenv, the sudo in beginning is not needed.
This has been bothering me as well for a while. I don't know the internals enough about python distutils etc, but the include path here is wrong. I made the following ugly hack to hold me over until the python lxml people can do the proper fix.
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2/libxml/ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml
Installing globally... OS X 10.9.2
xcode-select --install
sudo easy_install pip
sudo CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install lxml
instalation instructions on http://lxml.de/installation.html explain:
To speed up the build in test environments, e.g. on a continuous integration server, disable the C compiler optimisations by setting the CFLAGS environment variable:
CFLAGS="-O0" pip install lxml
None of the above worked for me on 10.9.2, as compilation bails out with following error:
clang: error: unknown argument: '-mno-fused-madd'
Which actually lead to cleanest solution (see more details in [1]):
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
pip install lxml
or following if installing globally
sudo pip install lxml
[1] clang error: unknown argument: '-mno-fused-madd' (python package installation failure)
xcode-select --install
sudo easy_install pip
sudo pip install lxml
I solved this issue on Yosemite by running the following commands:
xcode-select install #this may take several minutes.
pip install lxml
With homebrew, libxml2 is hidden to not interfere with the system libxml2, so pip must be helped a little in order to find it.
With bash:
LDFLAGS=-L`brew --prefix libxml2`/lib CPPFLAGS=-I`brew --prefix libxml2`/include/libxml2 pip install --user lxml
With fish:
env LDFLAGS=-L(brew --prefix libxml2)/lib CPPFLAGS=-I(brew --prefix libxml2)/include/libxml2 pip install --user lxml
I tried all the answers on this page, none of them worked for me. I'm running OS X Version 10.9.2
But this definitely works....like a charm:
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install lxml
OSX 10.9.2
sudo env ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future STATIC_DEPS=true pip install lxml
Unfortunately xcode-select --install did not work for me as I already had the latest version.
It's very strange but I solved the issue by opening XCode and accepting the Terms & Conditions. Re-running pip install lxml returned no errors after.
After successful install from pip (lxml 3.6.4) I was getting an error when importing the lxml.etree module.
I was searching endlessly to install this as a requisite for scrapy, and tried all the options, but finally this worked for me (mac osx 10.11 python 2.7):
$ STATIC_DEPS=true sudo easy_install-2.7 "lxml==2.3.5"
The older version of lxml seem to work with etree module.
Pip can often ignore the specified version of a package, for example when you have the newer version in the pip cache, thus the easy_install. The '-2.7' option is for python version, omit this if you are installing for python 3.x.
In my case, I must shutdown Kaspersky Antivirus before installing lxml by:
pip install lxml
before compiling add the path that to xmlversion.h into your environment.
$ set INCLUDE=$INCLUDE:/private/tmp/pip_build_root/lxml/src/lxml/
But make sure the path I've provided has the xmlversion.h file located inside. Then,
$ python setup.py install
pip did not work for me. I went to
https://pypi.python.org/pypi/lxml/2.3
and downloaded the macosx .egg file:
https://pypi.python.org/packages/2.7/l/lxml/lxml-2.3-py2.7-macosx-10.6-intel.egg#md5=52322e4698d68800c6b6aedb0dbe5f34
Then used command line easy_install to install the .egg file.
This post links to a solution that worked for me
Python3, lxml and "Symbol not found: _lzma_auto_decoder" on Mac OS X 10.9
hth
I met the same question and after days of working I resolved this problem on my OS X 10.9.4, with Python 3.4.1.
Here's my solution,
According to installing lxml from lxml.de,
A macport of lxml is available. Try something like port install py25-lxml
If you do not have MacPort, install it from MacPort.org. It's quite easy. You may also need a compiler, to install Xcode compiling tools, use xcode-select --install
Firstly I updated my port to the latest version via sudo port selfupdate,
Then I just type sudo port install libxml2 and several minutes later you should see libxml2 installed successfully. Probably you may also need libxslt to install lxml. To install libxslt, use:sudo port install libxslt.
Now, just type pip install lxml, it should work fine.
I am using OSX 10.9.2 and I get the same error.
Installation of the Xcode command line tools does not help for this particular version of OSX.
I think a better approach to fix this is to install with the following command:
$ CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 pip install lxml
This is similar to jdkoftinoff' fix, but does not alter your system in a permanent way.
After much tearing of the hair and gnashing of the teeth, I uninstalled Xcode with pip and ran:
easy_install lxml
And all was well.
Try:
% STATIC_DEPS=true pip install lxml
Or:
% STATIC_DEPS=true sudo pip install lxml
It works!

How do I update a Python package?

I'm running Ubuntu 9:10 and a package called M2Crypto is installed (version is 0.19.1). I need to download, build and install the latest version of the M2Crypto package (0.20.2).
The 0.19.1 package has files in a number of locations including (/usr/share/pyshared and /usr/lib/pymodules.python2.6).
How can I completely uninstall version 0.19.1 from my system before installing 0.20.2?
The best way I've found is to run this command from terminal
sudo pip install [package_name] --upgrade
sudo will ask to enter your root password to confirm the action.
Note: Some users may have pip3 installed instead. In that case, use
sudo pip3 install [package_name] --upgrade
You might want to look into a Python package manager like pip. If you don't want to use a Python package manager, you should be able to download M2Crypto and build/compile/install over the old installation.
To automatically upgrade all the outdated packages (that were installed using pip), just run the script bellow,
pip install $(pip list --outdated | awk '{ print $1 }') --upgrade
Here, pip list --outdated will list all the out dated packages and then we pipe it to awk, so it will print only the names.
Then, the $(...) will make it a variable and then, everything is done auto matically. Make sure you have the permissions. (Just put sudo before pip if you're confused)
I would write a script named, pip-upgrade
The code is bellow,
#!/bin/bash
sudo pip install $(pip list --outdated | awk '{ print $1 }') --upgrade
Then use the following lines of script to prepare it:
sudo chmod +x pip-upgrade
sudo cp pip-upgrade /usr/bin/
Then, just hit pip-upgrade and voila!
Via windows command prompt, run: pip list --outdated
You will get the list of outdated packages.
Run: pip install [package] --upgrade
It will upgrade the [package] and uninstall the previous version.
To update pip:
py -m pip install --upgrade pip
Again, this will uninstall the previous version of pip and will install the latest version of pip.
Method 1: Upgrade manually one by one
pip install package_name -U
Method 2: Upgrade all at once (high chance rollback if some package fail to upgrade
pip install $(pip list --outdated --format=columns |tail -n +3|cut -d" " -f1) --upgrade
Method 3: Upgrade one by one using loop
for i in $(pip list --outdated --format=columns |tail -n +3|cut -d" " -f1); do pip install $i --upgrade; done
I think the best one-liner is:
pip install --upgrade <package>==<version>
Open Command prompt or terminal and use below syntax
pip install --upgrade [package]==[specific version or latest version]
For Example
pip install --upgrade numpy==1.19.1
How was the package originally installed? If it was via apt, you could just be able to do apt-get remove python-m2crypto
If you installed it via easy_install, I'm pretty sure the only way is to just trash the files under lib, shared, etc..
My recommendation in the future? Use something like pip to install your packages. Furthermore, you could look up into something called virtualenv so your packages are stored on a per-environment basis, rather than solely on root.
With pip, it's pretty easy:
pip install m2crypto
But you can also install from git, svn, etc repos with the right address. This is all explained in the pip documentation
pip install -U $(pip list --outdated | awk 'NR>2 {print $1}')
In Juptyer notebook, a very simple way is
!pip install <package_name> --upgrade
So, you just need to replace with the actual package name.
How can I completely uninstall version 0.19.1 from my system before
installing 0.20.2?
In order to uninstall M2Crypto use
pip uninstall M2Crypto
I need to download, build and install the latest version of the
M2Crypto package (0.20.2).
In order to install the latest version, one can use PyPi
pip install M2Crypto
To install the version 20.2 (an outdated one), run
pip install M2Crypto==0.20.2
Assuming one just wants to upgrade
pip install M2Crypto --upgrade # Or pip install M2Crypto -U
Notes:
Depending on one's Python version (here's how to find the version) one may use a different pip command. Let's say one is working with Python 3.7, instead of just using pip, one might use pip3.7.
Using sudo is considered unsafe.
Nowadays there are better practices to manage the development system, such as: virtual environments or development containers. The development containers allow one to put the entire development environment (be it modules, VS Code extensions, npm libraries,...) inside a Docker container. When the project comes to an end, one closes the container. There's no need to keep all of those requirements around in the computer for no reason. If you feel like reading more about it: Visual Studio Docs, Github.
Get all the outdated packages and create a batch file with the following
commands
pip install xxx --upgrade for each outdated packages
I.e.:
python -m pip install --proxy <proxyserver_name>:<port#> <pkg_name>
Remember to export the variables after setting them, to make them available to the outer shell session.
Windows:
Add to environment variables:
set HTTP_PROXY=<proxyserver_name>:<port#>
You might have to install the full python package first

Categories