134

Long story short my work computer has network constraints which means trying to use pip install in cmd just leads to timing out/not finding package errors.

For example; when I try to pip install seaborn: enter image description here

Instead I have tried to download the tar.gz file of the packages I want, however, I do not know how to install them. I've extracted the files from the tar.gz file and there is a "setup" file within but it's not doing much for me.

If someone could explain how to install python packages in this manner without using pip install on windows that would be amazing.

yenoolnairb
  • 1,493
  • 2
  • 10
  • 12

8 Answers8

213

You may use pip for that without using the network. See in the docs (search for "Install a particular source archive file"). Any of those should work:

pip install relative_path_to_seaborn.tar.gz    
pip install absolute_path_to_seaborn.tar.gz    
pip install file:///absolute_path_to_seaborn.tar.gz    

Or you may uncompress the archive and use setup.py directly with either pip or python:

cd directory_containing_tar.gz
tar -xvzf seaborn-0.10.1.tar.gz
pip install seaborn-0.10.1
python setup.py install

Of course, you should also download required packages and install them the same way before you proceed.

Jérôme
  • 13,328
  • 7
  • 56
  • 106
  • This gives the following error: `You must give at least one requirement to install (maybe you meant "pip install file:///absolute path.."?)` – yenoolnairb Mar 15 '16 at 14:54
  • and I have actually entered the path in case you're wondering! – yenoolnairb Mar 15 '16 at 14:55
  • If you can download on another machine and bring them over, it's possible to download each dependency you need and install them in this manner in such an order that the desired package has all dependencies met and does not need a network connection anymore. I.e., `A` depends on `B`. So install `B`, then `A`. – Hawkins Mar 26 '18 at 17:19
37

You can install a tarball without extracting it first. Just navigate to the directory containing your .tar.gz file from your command prompt and enter this command:

pip install my-tarball-file-name.tar.gz

I am running python 3.4.3 and this works for me. I can't tell if this would work on other versions of python though.

Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90
  • 5
    Running this on python 3.4.3 and pip 9.0.1 I get an error relating to a temp file: `[Errno 2] No such file or directory: '/tmp/pip-anjip21-build/setup.py` running on Jessie (raspberry pi 3) – Magic_Matt_Man Feb 17 '17 at 11:09
  • @Magic See the [examples in official docs](https://pip.pypa.io/en/stable/reference/pip_install/#examples). So it _should_ work. From the error message you showed it seems the tarball you are trying to install isn't following proper file naming conventions. – Sнаđошƒаӽ Feb 28 '19 at 00:54
  • 1
    pip install *.tar.gz will install all the packages in the directory... just trying to help:) – Lev Aug 07 '19 at 15:57
11

Thanks to the answers below combined I've got it working.

  • First needed to unpack the tar.gz file into a folder.
  • Then before running python setup.py install had to point cmd towards the correct folder. I did this by pushd C:\Users\absolutefilepathtotarunpackedfolder
  • Then run python setup.py install

Thanks Tales Padua & Hugo Honorem

yenoolnairb
  • 1,493
  • 2
  • 10
  • 12
  • Can you edit the PATH variables of your machine? If so, you can add python to it, and use python anywhere without need to use pushd – Tales Pádua Mar 15 '16 at 16:21
  • 1
    Actually you don't have to extract the tar.gz file to install it. Take a look at [my answer](http://stackoverflow.com/a/37393114/3375713) – Sнаđошƒаӽ May 23 '16 at 14:04
8

Install it by running

python setup.py install

Better yet, you can download from github. Install git via apt-get install git and then follow this steps:

git clone https://github.com/mwaskom/seaborn.git
cd seaborn
python setup.py install
Tales Pádua
  • 1,331
  • 1
  • 16
  • 36
  • `No such file or directory` This could be to do with the setup of my files and folders. Python isn't gonna be in the default place Python would normally install – yenoolnairb Mar 15 '16 at 14:56
  • unpack from tar, go to the folder where the setup.py is, and then run the command above – Tales Pádua Mar 15 '16 at 14:58
  • Do I need to amend the code above to point it directly to where the unpacked tar is? Cos I'm still getting `no such file or directory` – yenoolnairb Mar 15 '16 at 14:59
  • Unpack the tar.gz to somewhere. Then, from the terminal, go to the folder where you extracted it. You need to be on the folder where setup.py is, and then run this command – Tales Pádua Mar 15 '16 at 15:01
  • Unfortunatley github is blocked on my work computer!! I've got it working now though; thanks – yenoolnairb Mar 15 '16 at 15:15
  • You can also use [pip + git](https://pip.readthedocs.org/en/stable/reference/pip_install/#git) but I assumed network issues ruled out this option. – Jérôme Mar 15 '16 at 16:25
6

If you don't wanted to use PIP install atall, then you could do the following:

1) Download the package 2) Use 7 zip for unzipping tar files. ( Use 7 zip again until you see a folder by the name of the package you are looking for. Ex: wordcloud)

Folder by Name 'wordcloud'

3) Locate Python library folder where python is installed and paste the 'WordCloud' folder itself there

Python Library folder

4) Success !! Now you can import the library and start using the package.

enter image description here

SVK
  • 1,004
  • 11
  • 25
  • 1
    This works perfect for situations where using pip generates `error(10054, 'An existing connection was forcibly closed by the remote host')` – adin Apr 30 '19 at 19:10
  • 1
    I was getting a whole host of different errors using the other solutions -- this was the only solution that worked for me – Bilbottom Apr 20 '21 at 08:23
  • Ciao I tried with the openpyxl-3.1.2.tar.gz so as you suggested I've unzipped untill I got the folder without tar.gz, and copied it into the python\lib. Once I've done this I've tried to run the import openpyxl and it didn't work. Error received: cannot import name 'load_workbook' from 'openpyxl' – martinmistere Apr 04 '23 at 14:55
5

For those of you using python3 you can use:

python3 setup.py install
mx0
  • 6,445
  • 12
  • 49
  • 54
Shersha Fn
  • 1,511
  • 3
  • 26
  • 34
0

Is it possible for you to use sudo apt-get install python-seaborn instead? Basically tar.gz is just a zip file containing a setup, so what you want to do is to unzip it, cd to the place where it is downloaded and use gunzip -c seaborn-0.7.0.tar.gz | tar xf - for linux. Change dictionary into the new seaborn unzipped file and execute python setup.py install

Deusdeorum
  • 1,426
  • 2
  • 14
  • 23
  • Okey, so he could use another unzipper like 7-zip, it's pretty irrelevant what unzipper he uses.. – Deusdeorum Mar 15 '16 at 14:56
  • might be, anyhow, the instructions are: unzip the folder -> change dictionary in your command line into that folder -> execute `python setup.py install` – Deusdeorum Mar 15 '16 at 15:00
0

I had a similar problem when I was working on an Oracle Enterprise Linux 6 (OEL 6) system that had Python 2.6.6 installed. I downloaded the tar file from the Python Package Index (PyPI) and installed it using the easy_install command. In my case, I was trying to install the virtualenv package. I followed these steps to install it:

  1. Download the tar file from pypi. Eg: virtualenv

    wget https://files.pythonhosted.org/packages/b1/72/2d70c5a1de409ceb3a27ff2ec007ecdd5cc52239e7c74990e32af57affe9/virtualenv-15.2.0.tar.gz

  2. Install the package from tar file.

    easy_install virtualenv-15.2.0.tar.gz

Thejesh PR
  • 935
  • 9
  • 14