Python pip package installation - python

What's the difference between
pip install pkg_name and
pip install -U pkg_name?
Does it automatically install the dependencies too or something?

If we do pip install -h we see:
-U, --upgrade Upgrade all specified packages to the newest
available version.
So it upgrades the packages you specify (they can be already installed)

Related

Can't upgrade or remove pip package "altgraph" on MacOs(Mojave)

I want to install PyInstaller package through pip, So I typed "pip install pyinstaller", but it occur errors
and I was trying to upgrade the alt graph to latest version.. but it occur same errors
how can I install the PyInstaller or how can I upgrade the package altgraph ?
Therefore, even I can't delete altgraph using
rm -rf /System/Library/Frameworks/Python.framework/.../altgraph
What I did in terminal
pip install pyinstall - not working
pip install --upgrade altgraph - not working
pip uninstall altgraph - not working
I found a solution from
http://marcelog.github.io/articles/mac_osx_python_pip_install_operation_not_permitted.html
install package under a user
pip install <package> --user

How to upgrade pip3?

I want to use python3.5 for development, but many times when I install the module for python 3.5, it always fails. The terminal tells me that a higher version is available, but it doesn't work when I upgrade it.
You are using pip3 to install flask-script which is associated with python 3.5. However, you are trying to upgrade pip associated with the python 2.7, try running pip3 install --upgrade pip.
It might be a good idea to take some time and read about virtual environments in Python. It isn't a best practice to install all of your packages to the base python installation. This would be a good start: http://docs.python-guide.org/en/latest/dev/virtualenvs/
To upgrade your pip3, try running:
sudo -H pip3 install --upgrade pip
Your pip may move from /bin to /usr/local/bin
To upgrade pip as well, you can follow it by:
sudo -H pip2 install --upgrade pip
Try this command:
pip3 install --upgrade setuptools pip
First decide which pip you want to upgrade, i.e. just pip or pip3.
Mostly it'll be pip3 because pip is used by the system, so I won't recommend upgrading pip.
The difference between pip and pip3 is that
NOTE: I'm referring to PIP that is at the BEGINNING of the command
line.
pip is used by python version 2, i.e. python2
and
pip3 is used by python version 3, i.e. python3
For upgrading pip3: # This will upgrade python3 pip.
pip3 install --upgrade pip
For upgrading pip: # This will upgrade python2 pip.
pip install --upgrade pip
This will upgrade your existing pip to the latest version.
The Problem
You use pip (the Python 2 one). Now you want to upgrade pip (the Python 3 one). After that, pip is the Python 3 one.
The solution
Use pip2 and pip3. This way it is explicit.
If you want to use pip, just check where it is (which pip) and change the link. For example:
$ which pip
/usr/local/bin/pip
$ pip --version
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
$ which pip2
/usr/local/bin/pip2
$ sudo rm /usr/local/bin/pip
$ sudo ln -s /usr/local/bin/pip2 /usr/local/bin/pip
$ pip --version
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
for Python 3:
python3 -m pip install --upgrade pip
for Python 2:
python2 -m pip install --upgrade pip
What worked for me was the following command:
python -m pip install --upgrade pip
pip3 install --upgrade pip worked for me
In Ubuntu 18.04, below are the steps that I followed.
python3 -m pip install --upgrade pip
For some reason you will be getting an error, and that be fixed by making bash forget the wrongly referenced locations using the following command.
hash -r pip
If you have 2 versions of Python (eg: 2.7.x and 3.6), you need do:
add the path of 2.x to system PATH
add the path of 3.x to system PATH
pip3 install --upgrade pip setuptools wheel
for example, in my .zshrc file:
export PATH=/usr/local/Cellar/python#2/2.7.15/bin:/usr/local/Cellar/python/3.6.5/bin:$PATH
You can exec command pip --version and pip3 --version check the pip from the special version. Because if don't add Python path to $PATH, and exec pip3 install --upgrade pip setuptools wheel, your pip will be changed to pip from python3, but the pip should from python2.x
This worked for me (mac)
sudo curl https://bootstrap.pypa.io/get-pip.py | python
If you try to run
sudo -H pip3 install --upgrade pip3
you will get the following error:
WARNING: You are using pip version 19.2.3, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
but if you upgrade using the suggested command:
pip install --upgrade pip
then, the legacy pip will be upgraded, so what I did is the following:
which pip3
and I located my pip3 installation (just in case the following command wouldn't upgrade the legacy pip. Then i changed to that directory and upgraded pip3 using the following commands: (your directory could be different)
cd /Library/Frameworks/Python.framework/Versions/3.8/bin
sudo -H pip3 install --upgrade pip
after this:
pip --version
will still show the legacy version, while
pip3 --version
will show pip 21.0.1

Pip doesn't show my installed packages

pip won't show my installed packages.
I did
brew install python
sudo -E pip install virtualenv
pip list
pip (1.5.6)
setuptools (5.4.2)
wsgiref (0.1.2)
Why isn't pip showing virtualenv?
This pip is the version installed by brew.
When I installed python, it says:
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
Looking in this directory, virtualenv is not there.
Doing an updatedb; locate virtualenv, I find it installed here:
/lib/python2.7/site-packages/
What gives? Pip installs to above location, but isn't aware of it when I do pip list!
EDIT: In response to #jordanm's comment,
sudo -E pip install virtualenv
Password:
Downloading/unpacking virtualenv
Downloading virtualenv-1.11.6-py2.py3-none-any.whl (1.6MB): 1.6MB downloaded
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...
sudo -E pip install virtualenv most likely installs virtualenv to OSX provided system-wide Python installation, not Homebrew installed Python.
Try:
brew install pyenv-virtualenv
instead.

pip install -e: new library needed: how to get them

I installed a library "editable" with "pip install -e".
The library has updated the setup.py and new dependencies (install_requires=...) are required.
What should I do, to fetch the new dependencies?
I could install them manually. But an automatic resolve like on "pip install" would be nice.
Use the upgrade option:
$ pip install -h
...
-U, --upgrade Upgrade all packages to the newest available version
So: pip install -U editable

Package in pypi not installable by pip

Why can't I use
$ sudo pip install facebook-python-sdk
even with facebook-python-sdk package in pypi?
log: http://dpaste.com/hold/589044/
Not sure what's going on there, but you can use pip to install from the github repo:
pip install git+https://github.com/facebook/python-sdk.git\#egg=facebook-python-sdk
I usually use pip install -e which makes pip symlink the package for you, so you can edit the repo, update it etc, and get the latest changes without having to pip install again.

Categories