`pip` doesn't upgrade itself - python

I can't upgrade pip (9.0.1) to pip (10.0.1).
Running
pip install --upgrade pip
throws
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/EGG-INFO/PKG-INFO'
(this is yet another issue I will need to deal with...)
Trying
pip install --user pip
returns
Requirement already satisfied: pip in /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
and has no effect, i.e. pip list | grep pip returns pip (9.0.1)
Running
pip install --upgrade --user pip
returns
Successfully installed pip-10.0.1
but pip list | grep pip still returns pip (9.0.1)
I have learned not to use sudo, so please don't suggest this.
This answer suggests to install by hand (more or less). But I am worried of messing things up.
If you are suggesting to use a virtual environment, I am afraid this is one level of sophistication too many for me as I am still very much a beginner, and if something doesn't work the way it should I will find it even more daunting to figure out what to try.
Is there really no alternative than the latter options?

You can "safely" delete everyting in /Library/Python/2.7/site-packages/, except for:
$ cat Extras.pth
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
You can do it from the Finder (it should ask for your Admin credentials) or in a pinch with sudo rm - carful!
I'd recommend removing everything there - which should get rid of any packages you previously installed with pip or easy_install - and only ever using pip install --user from then on or better yet use pyenv from homebrew to get Python 3 and use virtual environments from then on.

Related

Pip cannot install anything on ubuntu server

I had deleted an existing virtual environment. I created a new one and activated it. Now I am trying to install site packages using
pip install -r requirements.txt
But I keep getting the error
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement BeautifulSoup==3.2.1 (from -r requirements.txt (line 1))
Now I know that the packages are really old but this is running on python 2.7.6. I am also not able to install anything through pip. I have tried
pip install numpy
But it shows the same errors. As per the similar questions answered before the suggestion is to use https://pypi.python.org which I have already done but still facing these errors.
Would love to hear your suggestions.
Might be a problem with having an old version of pip.
Try pip install --upgrade pip and then try installing the requirements again.
pip tries to create lockfile in cache directory
Try running pip install --upgrade pip --no-cache-dir

pip is rolling back

I have a problem with the pip python 3.x installation.
I have pip version 19.0.3, but when i use pycharm, it keeps saying that i need the pip updated.
when i check the folder, I can see there is another version of pip pip-10.0.1-py3.7.egg in the folder.
I remember ticking the option to add the python in the environment path when i installed python.
When I tried to update/install pip again, i got the error.
(venv) C:\Users\ranic\PycharmProjects\ProjectDatabase>pip help install
You are using pip version 10.0.1, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
(venv) C:\Users\r\PycharmProjects\ProjectDatabase>python -m pip install --upgrade pip
Requirement already up-to-date: pip in c:\users\r\pycharmprojects\projectdatabase\venv\lib\site-packages (19.0.3)
Thank you in advance.
If you check, I guarantee that pip is not in the same place as python.
Mine are, seen below:
C:\Users\adsmith>where pip
C:\Users\adsmith\AppData\Local\Programs\Python\Python36-32\Scripts\pip.exe
C:\Users\adsmith>where python
C:\Users\adsmith\AppData\Local\Programs\Python\Python36-32\python.exe
but I'm guessing your python is referring to Python2, and pip Python3 (or vice versa). If you find the version of Python that pip refers to, you should be able to do:
path/to/that/python -m pip install --upgrade pip

pip install with brute force (no prompts)

Is there a way to install packages with pip to avoid the need to repeatedly delete files like:
pip can't proceed with requirement 'Flask-Restless==0.13.1 (from -r requirements.txt (line 2))' due to a pre-existing build directory.
location: /private/var/folders/0k/t9lwmd2j1212pxydpr6l596h0000gq/T/pip_build_jacob/Flask-Restless
This is likely due to a previous installation that failed.
pip is being responsible and not assuming it can delete this.
I'm on round 4 of doing this and have no idea how long it may take to get through.
Looking at pip --help isn't helpful and man pip returns nothing.
As it has already been mentioned it's better to use virtualenv in order to avoid python package chaos on your system and install the python packages only for particular projects.
However, in your particular case you can try the following in the terminal:
pip uninstall flask-restless
Then try to run the installation again:
pip install -r requirements.txt
The options to consider during installation:
--force-reinstall
--ignore-installed
--no-deps
Add these options to the end of pip install -r requirements.txt to play with them and see if they can help.
Using
--force-reinstall
may solve your issue.
I would also recommend considering using a virtualenv for each project you are working on.
https://virtualenv.pypa.io/en/stable/
You can then activate the virtual environment for that project and pip
pip install -r requrements.txt
will install dependencies for that project in the virtual environment instead of globally. This will reduce the odds of having weird conflicts like you are having and if you do have an issue you can blow away the virtualenv and reinstall just the dependencies for that project without borking your global packages.

Can't install Pip Packages in El Capitan (10.11)

Okay, so I have brew, and I've brew reinstalled python since El Capitan.
MacBook-Pro-2:decipher Alex$ which python
/usr/local/bin/python
MacBook-Pro-2:decipher Alex$ whereis python
/usr/bin/python
I have two pythons. That's all well and good. Brew doctor is clean, except for some Unbrewed header files were found in /usr/local/include, none of which seem related to Python. Short of virtualenv, is there any way to install packages anymore? I feel like I might be missing something.
Just like this guy I was trying to get IPython. I don't really need it, so I gave up the other day. Now I need Pylint. If I try to install it with pip:
IOError: [Errno 13] Permission denied: '/lib/python2.7/site-packages/logilab_common-1.1.0-py2.7-nspkg.pth'
Does anyone know how to point pip towards another instance of python on my system, or do something else so I can have the old behavior back? Please?
-- EDITS --
Suggested was the idea of using /usr/local/bin/pip to install ipython. This is the output. I can't figure out how to use ipython still.
MacBook-Pro-2:MNIST Alex$ /usr/local/bin/pip install ipython[all]
Requirement already satisfied (use --upgrade to upgrade): ipython[all] in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): traitlets in /usr/local/bin (from ipython[all])
Requirement already satisfied (use --upgrade to upgrade): pickleshare in /usr/local/bin (from ipython[all])
Requirement already satisfied (use --upgrade to upgrade): simplegeneric>0.8 in /usr/local/bin (from ipython[all])
... the rest of the requirements are all satisfied in usr/local/bin
I had trouble too with El Capitan. I did these things and it worked:
1) Install Homebrew
2) Install Python 3 with Homebrew
3) In terminal enter these installs (in this order)
$ pip3 install pyobjc-core
$ pip3 install pyobjc
$ pip3 install pillow
$ pip3 install pyautogui
To point pip to another Python instance of your system, you need to use pip from the same bin/ folder where python is installed so it resolves to the same site-packages.
Example:
/usr/local/bin/pip install logilab_common
To make /usr/local/ writable by a local user on OSX do:
sudo chown -R `whoami`:admin /usr/local/*
More information
http://blog.blakesimpson.co.uk/read/89-fix-homebrew-error-usr-local-bin-is-not-writable-on-os-x-el-capitan
As Mikko Ohtamaa points out in the comments, somehow, I had a version of python in a folder called /lib. I'm not sure how it got there. I think that's the version of python I was using. Once I just sudo rm -rf /lib everything suddenly worked.

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