Installing modules to Anaconda from .tar.gz
Asked Answered
S

6

40

When I want to install modules to Anaconda, I run conda install. However, now I have a .tar.gz file and want to install this. How to do?

Sickle answered 18/7, 2017 at 1:36 Comment(1)
did you try conda install <pkg.tar>?Provided
S
54

There are several ways to achieve this, I'm describing one here, which should be relatively straight forward, even if your default python variable is not anaconda's.

  1. Check what is your desired anaconda environment (if you're not sure what does this mean, it probably means that you are using root, the default environment)
  2. Run: conda info --envs to see the path where your environment is installed
  3. Go to that path, and find the absolute path to python.exe, for example: "C:\Program Files\Anaconda3\python.exe"
  4. Now, run the following command:

<absolute path to python.exe> -m pip install <path to tar.gz>

for example:

C:\Program Files\Anaconda3\python.exe -m pip install c:\mymodule\great.tar.gz

Note that <path to tar.gz> can be relative, absolute and even an online link.

Slumgullion answered 18/7, 2017 at 13:0 Comment(6)
Just an addition for the noobs in python like me. If you use Anaconda, replace 'pip' to 'conda'Etruscan
Edit: Actually, might be not true. Sorry for the confusion.Etruscan
@FloridaMan It depends where the tar.gz file comes from.Wheatley
It still looks for the package in the repos. Adding --offline field with conda also does not help.I am also trying to do a local install without needing internet connection.Barrel
why didn't you suggest conda install <pkg.tar>?Provided
what if my package comes from here: public.dhe.ibm.com/ibmdl/export/pub/software/server/ibm-ai/…Provided
W
19

It depends on where your archive comes from:

  • If you got it from pypi, you need to install it using pip:
pip install package.tar.gz
# Or:
python -m pip install package.tar.gz
  • If you got it from conda-forge, you need to use conda:
conda install package.tar.gz

If you have multiple python installations, you may need to specify absolute path to the python/conda executable.

Note that the archive files on pypi and conda-forge are usually very different:

  • pypi archives contain source files, so you may need to build the package in order to install it, which may requires external dependencies;
  • conda-forge are architecture-specific and contains pre-built package, which are much less likely to require external dependencies.

If you already have a working Anaconda distribution, I would encourage you to get archives from conda-forge instead of pypi.

Wheatley answered 15/3, 2018 at 14:36 Comment(5)
I just tried installing numpy this way. It doesn't work for me. It seems like conda install package.tar.gz does not grab any dependencies.Sprit
Here's some more info about it github.com/conda/conda/issues/1884Sprit
And how would I know if it is pypi or conda-forge, if the URL is e.g., anaconda.org/anaconda/dal/… as described here?Crystalloid
@sancho.sReinstateMonicaCellio If it's from the anaconda registry, it's a conda package, so conda install.Wheatley
I guess that is even if not from conda-forge. Perhaps it is useful to clarify this point in the answer...Crystalloid
D
3

Here is how to do :

Q:\anaconda3\Scripts>conda install q:\quandl-3.4.4-py37_0.tar.bz2

Downloading and Extracting Packages

########################################################################################### 
#################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

Q:\anaconda3\Scripts>
Devan answered 3/1, 2019 at 15:59 Comment(0)
I
2

Just a PSA please don't use conda install <pkg.tar> when updating python from a tar.bz. This has the potential to break Anaconda.

Insert answered 16/2, 2021 at 16:13 Comment(1)
Comment, I lack credit to post it as such. I only added it as an answer to prevent others from following the general comment at the top of the thread. I'l gladly remove it if you know a way for me / someone else to add it as a comment.Insert
S
1

If you are using Anaconda and downloaded the package from Anaconda Cloud, then you can place your "package.tar.bz2" files in the path shown in Anaconda prompt (Eg. C:\Users) and type in the following command in Anaconda Prompt

conda install package.tar.bz2

I believe it will work for .tar.gz files too.

Startle answered 8/9, 2018 at 14:10 Comment(0)
C
0

For computers without a network, you can install packages with the following steps:

Conda install <file.tar.bz2> still does not install dependencies #1884 stuarteberg

  1. Create a directory to serve as the local channel, with a subdirectory for your platform (OS). Note: it should be in the format mentioned here. Otherwise conda can not recognize it (at least from my situation).
  2. Move your package tarball into that subdirectory.
  3. Run conda index on the local channel directory.
  4. Run conda install -c file://${my_local_channel}
mkdir -p /tmp/my-local-channel/osx-64
mv ~/Downloads/mypackage-2.40-py37hc48c483_1.tar.bz2 /tmp/my-local-channel/osx-64
conda index /tmp/my-local-channel
conda install -c file:///tmp/my-local-channel mypackage

You may encounter CondaHTTPError, I solved this by adding params: conda install -c file:///tmp/my-local-channel --no-deps --offline mypackage. Please be aware of the risks behind these params.

Because I'm a rookie, feel free to correct me.

Cathern answered 15/4 at 7:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.