如何以轮格式安装 Python 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21222114/
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
How do I install Python libraries in wheel format?
提问by user3212988
I was looking for a tutorial on how to install Python libraries in the wheel format.
我正在寻找有关如何以轮格式安装 Python 库的教程。
It does not seem straightforward so I'd appreciate a simple step by step tutorial how to install the module named "requests" for CPython.
它看起来并不简单,所以我很欣赏一个简单的分步教程,如何为 CPython 安装名为“requests”的模块。
I downloaded it from: https://pypi.python.org/pypi/requestsand now I have a .whl file. I've got Python 2.7 and 3.3 on Windows, so how do I install it so all the other Python scripts I run can use it?
我从:https: //pypi.python.org/pypi/requests下载它,现在我有一个 .whl 文件。我在 Windows 上安装了 Python 2.7 和 3.3,那么如何安装它以便我运行的所有其他 Python 脚本都可以使用它?
回答by Francisco Corrales Morales
Have you checked this http://docs.python.org/2/install/?
你检查过这个http://docs.python.org/2/install/吗?
First you have to install the module
$ pip install requestsThen, before using it you must import it from your program.
from requests import requestsNote that your modules must be in the same directory.
Then you can use it.
For this part you have to check for the documentation.
首先你必须安装模块
$ pip install requests然后,在使用它之前,您必须从您的程序中导入它。
from requests import requests请注意,您的模块必须在同一目录中。
然后你就可以使用它了。
对于这部分,您必须检查文档。
回答by Perefexexos
Install distribute by downloading and running distribute_setup.py. This will make easy_install available, and from there you can install pip with easy_install pip. Then you can run pip install CAGE. Using pip to install things is a lot easier than messing with manually running setup.py, because pip can do things like:
通过下载并运行distribute_setup.py 来安装distribute。这将使 easy_install 可用,然后您可以使用 easy_install pip 安装 pip。然后你可以运行 pip install CAGE。使用 pip 安装东西比手动运行 setup.py 要容易得多,因为 pip 可以执行以下操作:
automatically resolve dependencies
show you a list of all installed packages and their versions
install a set of specified packages from a requirements.txt
upgrade and uninstall packages
work with virtualenv
If you're on Windows, the one downside of pip occurs when there are C library dependencies, as pip will want a C toolchain installed so it can compile things. If that is the case, then there are two options. If there are precompiled binaries on PyPI, then just run easy_install package instead; easy_install knows how to use binary packages. You can also check Christoph Gohlke's sitefor executable installers of many binary packages. These can also be installed by easy_install if you want to use them with a virtualenv (just point it to the path of the .exe) or you can click and run if you don't care about virtualenv.
如果您在 Windows 上,当存在 C 库依赖项时会出现 pip 的一个缺点,因为 pip 需要安装 C 工具链以便它可以编译东西。如果是这种情况,那么有两种选择。如果 PyPI 上有预编译的二进制文件,那么只需运行 easy_install 包;easy_install 知道如何使用二进制包。您还可以在Christoph Gohlke 的站点上查看许多二进制包的可执行安装程序。如果您想将它们与 virtualenv 一起使用(只需将其指向 .exe 的路径),也可以通过 easy_install 安装它们,或者如果您不关心 virtualenv,则可以单击并运行。
The main point is that no matter what route you choose to install packages, at no point are you ever moving around files by hand. You need to get out of the mindset of "I extracted this archive, where do I put these .py files?" That's not how it works. You're either running pip, running easy_install, running setup.py, clicking on an installer package, or using your distribution's installer. At no point are you ever doing anything by hand with the files directly.
主要的一点是,无论您选择哪种方式安装软件包,您都不会手动移动文件。您需要摆脱“我提取了这个档案,我把这些 .py 文件放在哪里?”的心态。这不是它的工作原理。您要么运行 pip、运行 easy_install、运行 setup.py、单击安装程序包,要么使用发行版的安装程序。您从来没有直接手动处理文件。
回答by zurfyx
Once you have a library downloaded you can execute this from the MS-DOS command box:
下载库后,您可以从 MS-DOS 命令框执行此操作:
python setup.py install
The setup.pyis located inside every library main folder.
在setup.py位于每个库主文件夹内。
回答by Omid Raha
If you want to be relax for installing libraries for python.
如果你想放松一下为 python 安装库。
You should using pip, that is python installer package.
您应该使用pip,即 python 安装程序包。
To install pip:
要安装 pip:
Download ez_setup.pyand then run:
python ez_setup.pyThen download get-pip.pyand run:
python get-pip.pyupgrade installed
setuptoolsby pip:pip install setuptools --upgradeIf you got this error:
Wheel installs require setuptools >= 0.8 for dist-info support. pip's wheel support requires setuptools >= 0.8 for dist-info support.Add
--no-use-wheelto above cmd:pip install setuptools --no-use-wheel --upgrade
下载ez_setup.py,然后运行:
python ez_setup.py然后下载get-pip.py并运行:
python get-pip.pysetuptoolspip安装的升级:pip install setuptools --upgrade如果您收到此错误:
Wheel installs require setuptools >= 0.8 for dist-info support. pip's wheel support requires setuptools >= 0.8 for dist-info support.添加
--no-use-wheel到上面的cmd:pip install setuptools --no-use-wheel --upgrade
Now, you can install libraries for python, just by:
现在,您可以为 python 安装库,只需:
pip install library_name
For example:
例如:
pip install requests
Note that to install some library may they need to compile, so you need to have compiler.
注意安装一些库可能需要编译,所以你需要有编译器。
On windows there is a site for Unofficial Windows Binaries for Python Extension Packagesthat have huge python packages and complied python packages for windows.
在 Windows 上,有一个用于 Python 扩展包的非官方 Windows 二进制文件的站点,其中包含巨大的 Python 包和为 Windows 编译的 Python 包。
For example to install pipusing this site, justdownload and install setuptoolsand pipinstaller from that.
例如,要pip使用此站点进行安装,只需从该站点下载并安装setuptools和pipinstaller。
回答by T90
回答by Trilarion
You want to install a downloaded wheel (.whl) file on Python under Windows?
您想在 Windows 下在 Python 上安装下载的轮子 (.whl) 文件?
- Install pip on your Python(s) on Windows(on Python 3.4+ it is already included)
Upgrade pip if necessary (on the command line)
pip install -U pipInstall a local wheel file using pip (on the command line)
pip install --no-index --find-links=LocalPathToWheelFile PackageName
- 在 Windows 上的 Python(s) 上安装 pip(在 Python 3.4+ 上已经包含)
必要时升级 pip(在命令行上)
pip install -U pip使用pip(在命令行上)安装本地wheel文件
pip install --no-index --find-links=LocalPathToWheelFile PackageName
Option --no-indextells pip to not look on pypi.python.org (which would fail for many packages if you have no compiler installed), --find-linksthen tells pip where to look for instead. PackageNameis the name of the package (numpy, scipy, .. first part or whole of wheel file name). For more informations see the install optionsof pip.
Option--no-index告诉 pip 不要在 pypi.python.org 上查找(如果您没有安装编译器,很多包都会失败),--find-links然后告诉 pip 去哪里查找。PackageName是包的名称(numpy、scipy、.. 轮文件名的第一部分或全部)。有关更多信息,请参阅pip的安装选项。
You can execute these commands in the command prompt when switching to your Scriptsfolder of your Python installation.
切换到ScriptsPython 安装文件夹时,您可以在命令提示符下执行这些命令。
Example:
例子:
cd C:\Python27\Scripts
pip install -U pip
pip install --no-index --find-links=LocalPathToWheelFile PackageName
Note: It can still be that the package does not install on Windows because it may contain C/C++ source files which need to be compiled. You would need then to make sure a compiler is installed. Often searching for alternative pre-compiled distributionsis the fastest way out.
注意:该包仍然可能没有安装在 Windows 上,因为它可能包含需要编译的 C/C++ 源文件。然后您需要确保安装了编译器。通常,寻找替代的预编译发行版是最快的出路。
For example numpy-1.9.2+mkl-cp27-none-win_amd64.whlhas PackageNamenumpy.
例如numpy-1.9.2+mkl-cp27-none-win_amd64.whl有PackageNamenumpy.
回答by str8arrow
To install wheel packages in python 2.7x:
在 python 2.7x 中安装轮包:
Install python 2.7x (i would recommend python 2.78) - download the appropriate python binary for your version of windows . You can download python 2.78 at this site https://www.python.org/download/releases/2.7.8/-I would recommend installing the graphical Tk module, and including python 2.78 in the windows path (environment variables) during installation.
Install get-pip.py and setuptools Download the installer at https://bootstrap.pypa.io/get-pip.pyDouble click the above file to run it. It will install pip and setuptools [or update them, if you have an earlier version of either]
安装 python 2.7x(我会推荐 python 2.78) - 为你的 windows 版本下载合适的 python 二进制文件。您可以在此站点https://www.python.org/download/releases/2.7.8/下载 python 2.78 - 我建议安装图形 Tk 模块,并在安装过程中将 python 2.78 包含在 windows 路径(环境变量)中.
安装 get-pip.py 和 setuptools 在https://bootstrap.pypa.io/get-pip.py下载安装程序 双击上面的文件运行它。它将安装 pip 和 setuptools [或更新它们,如果您有早期版本]
-Double click the above file and wait - it will open a black window and print will scroll across the screen as it downloads and installs [or updates] pip and setuptools --->when it finishes the window will close.
- 双击上面的文件并等待 - 它将打开一个黑色窗口,打印将在下载和安装 [或更新] pip 和 setuptools 时在屏幕上滚动 ---> 完成后窗口将关闭。
- Open an elevated command prompt - click on windows start icon, enter cmd in the search field (but do not press enter), then press ctrl+shift+. Click 'yes' when the uac box appears.
- 打开提升的命令提示符 - 单击 Windows 开始图标,在搜索字段中输入 cmd(但不要按 Enter),然后按 ctrl+shift+。出现 uac 框时单击“是”。
A-type cd c:\python27\scripts [or cd \scripts ]
A 型 cd c:\python27\scripts [或 cd \scripts]
B-type pip install -u Eg to install pyside, type pip install -u pyside
B-type pip install -u 比如安装pyside,输入pip install -u pyside
Wait - it will state 'downloading PySide or -->it will download and install the appropriate version of the python package [the one that corresponds to your version of python and windows.]
等待 - 它将说明“正在下载 PySide 或 --> 它将下载并安装适当版本的 python 包[与您的 python 和 Windows 版本相对应的版本。]
Note - if you have downloaded the .whl file and saved it locally on your hard drive, type in
pip install --no-index --find-links=localpathtowheelfile packagename
注意 - 如果您已下载 .whl 文件并将其保存在本地硬盘上,请输入
pip install --no-index --find-links=localpathtowheelfile packagename
**to install a previously downloaded wheel package you need to type in the following command pip install --no-index --find-links=localpathtowheelfile packagename
**要安装之前下载的wheel包,您需要输入以下命令pip install --no-index --find-links=localpathtowheelfile packagename
回答by devDeejay
You don't need to download exclusively from the website. Just make sure you have pip (which you probably will if you have python installed). Just open your Command Prompt (CMD) and run the command:
您不需要专门从网站下载。只要确保你有 pip (如果你安装了 python,你可能会这样做)。只需打开您的命令提示符 (CMD) 并运行以下命令:
pip install pygame
It will automatically download the correct whl version of pygame compatible with your configuration of PC. Make sure you remember the version which appears while "downloading" as this is the compatible version of .whl packages you shall be looking for in the future.
它将自动下载与您的 PC 配置兼容的正确 whl 版本的 pygame。确保您记住“下载”时出现的版本,因为这是您将来要寻找的 .whl 软件包的兼容版本。
回答by Yusuf
Simple steps to install python in Ubuntu:
在 Ubuntu 中安装 python 的简单步骤:
Download Python
$ cd /usr/src $ wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgzExtract the downloaded package
$ sudo tar xzf Python-3.6.0.tgzCompile Python source
$ cd Python-3.6.0 $ sudo ./configure $ sudo make altinstallNote
make altinstallis used to prevent replacing the default python binary file/usr/bin/python.check the python version
# python3.6 -V
下载 Python
$ cd /usr/src $ wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz解压下载的包
$ sudo tar xzf Python-3.6.0.tgz编译 Python 源代码
$ cd Python-3.6.0 $ sudo ./configure $ sudo make altinstallNote
make altinstall用于防止替换默认的 python 二进制文件/usr/bin/python。检查python版本
# python3.6 -V
回答by DINA TAKLIT
i have write the answer here How to add/use libraries in Python (3.5.1)but no problem will rewrite it again
我在这里写了答案 How to add/use libraries in Python (3.5.1)但没问题会再次重写
if u have or you can create a file requirements.txtwhich contains the libraries that you want to install for ex:
如果你有或者你可以创建一个requirements.txt包含你想要安装的库的文件,例如:
numpy==1.14.2
Pillow==5.1.0
You gonna situate in your folder which contains that requirements.txtin my case the path to my project is
你将位于你的文件夹中,requirements.txt在我的情况下,我的项目路径是
C:\Users\LE\Desktop\Projet2_Sig_Exo3\exo 3\k-means
now just type
现在只需输入
python -m pip install -r ./requirements.txt
and all the libararies that you want gonna install
以及你想要安装的所有库
C:\Users\LE\Desktop\Projet2_Sig_Exo3\exo 3\k-means>python -m pip install -r ./requirements.txt

