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.
If you are running low on memory you could try with pip install <your-package-name> --no-cache-dir
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.
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.
- Create a swap file on the current File system for example on root, for this a new Directory can be created. $ sudo mkdir /swap
- 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
- Create a new swap area on the file that has been created. $ sudo mkswap /swap/swapfile1
- Change the permissions on the file. $ sudo chmod 600 /swap/swapfile1
- Add the swap partition to the /etc/fstab file as indicated below on this step: /swap/swapfile1 swap swap defaults 0 0
- Load the new swap space that had been created for the Instance. $ sudo swapon -a
Source for Guide: TheGeekDiary
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.
pip install package --no-cache-dir
If the problem persists, go to step 2.
sudo swapoff -a
sudo swapon -a
Then try step 1 again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With