如何在不使用 pip install 的情况下从 tar.gz 文件安装 Python 包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36014334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:17:28  来源:igfitidea点击:

How to install Python packages from the tar.gz file without using pip install

pythoninstallpackages

提问by yenoolnairb

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

长话短说,我的工作计算机有网络限制,这意味着尝试pip install在 cmd 中使用只会导致超时/找不到包错误。

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

例如; 当我尝试pip install seaborn在此处输入图片说明

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.

相反,我尝试下载我想要的软件包的 tar.gz 文件,但是,我不知道如何安装它们。我已经从 tar.gz 文件中提取了文件,里面有一个“设置”文件,但它对我没有多大作用。

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

如果有人能解释如何以这种方式安装 python 包而不pip install在 Windows 上使用,那将是惊人的。

采纳答案by yenoolnairb

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 installhad to point cmd towards the correct folder. I did this by pushd C:\Users\absolutefilepathtotarunpackedfolder
  • Then run python setup.py install
  • 首先需要将 tar.gz 文件解压到一个文件夹中。
  • 然后在运行之前python setup.py install必须将 cmd 指向正确的文件夹。我这样做了pushd C:\Users\absolutefilepathtotarunpackedfolder
  • 然后运行 python setup.py install

Thanks Tales Padua & Hugo Honorem

感谢 Tales Padua 和 Hugo Honorem

回答by Jér?me

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

您可以pip在不使用网络的情况下使用它。请参阅文档(搜索“安装特定源存档文件”)。其中任何一个都应该有效:

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.pydirectly with either pipor python:

或者您可以解压缩存档并setup.py直接使用pippython

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.

当然,在继续之前,您还应该下载所需的软件包并以相同的方式安装它们。

回答by Sна?ош?а?

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

您无需先解压即可安装 tarball。只需.tar.gz从命令提示符导航到包含文件的目录并输入以下命令:

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.

我正在运行 python 3.4.3,这对我有用。我不知道这是否适用于其他版本的 python。

回答by Tales Pádua

Install it by running

通过运行安装它

python setup.py install

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

更好的是,您可以从 github 下载。通过安装 git apt-get install git,然后按照以下步骤操作:

git clone https://github.com/mwaskom/seaborn.git
cd seaborn
python setup.py install

回答by Shersha Fn

For those of you using python3 you can use:

对于那些使用 python3 的人,你可以使用:

python3 setup.py install

回答by SVK

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

如果您根本不想使用 PIP 安装,那么您可以执行以下操作:

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)

1) 下载包 2) 使用 7 zip 解压 tar 文件。(再次使用 7 zip 直到您看到您要查找的包名称的文件夹。例如:wordcloud)

Folder by Name 'wordcloud'

按名称“wordcloud”的文件夹

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

3)找到安装python的Python库文件夹并将“WordCloud”文件夹本身粘贴到那里

Python Library folder

Python 库文件夹

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

4)成功!!现在您可以导入库并开始使用该包。

enter image description here

在此处输入图片说明

回答by Deusdeorum

Is it possible for you to use sudo apt-get install python-seaborninstead? 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

你可以用它sudo apt-get install python-seaborn代替吗?基本上 tar.gz 只是一个包含设置的 zip 文件,所以你要做的是解压缩它,cd 到它下载的地方并gunzip -c seaborn-0.7.0.tar.gz | tar xf -用于 linux。将字典更改为新的seaborn解压文件并执行python setup.py install