pip install - killed

PythonUbuntuPip

Python Problem Overview


I'm trying to install package with pip on Ubuntu server:

$ pip install MySQLdb
Downloading/unpacking MySQLdb
Killed

And it's getting killed. There is enough free RAM on server. Why it is killed?

UPD Logs:

> Out of memory: Kill process 6627 (pip) score 297 or sacrifice child

Thats strange, because I have about 150 mb free RAM.

Python Solutions


Solution 1 - Python

If you are running low on memory you could try with pip install package --no-cache-dir

Solution 2 - Python

You have to check logs, depending on the version of ubuntu and stuff, it should be in /var/log/messages or at least in /var/log so you can grep python or pip in that folder. This should provide hints.

Also, if you're not in a virtualenv, you should probably use sudo to perform (implicit) privileged operations, such as copying the library in the global lib folder.

Solution 3 - Python

If the --no-cache-dir flag isn't enough, try increasing the swap space.

I was trying to install PyTorch on a Linode server which had 2GB RAM and 512 of Swap space. Adding 2GB of Swap space solved the issue.

> Method # 3 : Create a swap file. > 1. Create a swap file on the current File system for example on root, for this a new Directory can be created. > $ sudo mkdir /swap > 2. Create a new file into this new directory, in this example a new file for 2Gb is create. > $ sudo dd if=/dev/zero of=/swap/swapfile1 bs=1M count=2048 > 3. Create a new swap area on the file that has been created. > $ sudo mkswap /swap/swapfile1 > 4. Change the permissions on the file. > $ sudo chmod 600 /swap/swapfile1 > 5. Add the swap partition to the /etc/fstab file as indicated below on this step: > /swap/swapfile1 swap swap defaults 0 0 > 6. Load the new swap space that had been created for the Instance. > $ sudo swapon -a

Source for Guide: TheGeekDiary

Solution 4 - Python

In my case the cleaning cache of pip by using pip3 cache purge was was the solution, but be careful: it removes the entire pip cache.

I have enough free RAM in idle state (~3Gb) but installation of torch being killed again and again, even without showing downoading progress:

Collecting torch>=1.5.0
Killed

So I supposed, just like @embiem guessed, that I had corrupted files in the cache, because I had aborted installation of the dependencies for the module once. After clearing the whole pip cache the installation was successful (And 15GB of free disk space was freed up - I use a lot of virtual environments). You can check brief info with pip3 cache info and all cache managing command pip3 cache -h, it's very useful in some cases.

Solution 5 - Python

Step1:

pip install package --no-cache-dir If the problem persists, go to step 2.

Step2:

sudo swapoff -a

sudo swapon -a

Then try step 1 again.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionartemView Question on Stackoverflow
Solution 1 - PythonJoaquínView Answer on Stackoverflow
Solution 2 - PythonAifView Answer on Stackoverflow
Solution 3 - PythonNavan ChauhanView Answer on Stackoverflow
Solution 4 - PythonferrumView Answer on Stackoverflow
Solution 5 - Pythonambition_skyView Answer on Stackoverflow