如何使用便携式 Python 安装外部库? [英] How to install external libraries with Portable Python?

查看:30
本文介绍了如何使用便携式 Python 安装外部库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于管理员权限,我无法在我的机器上安装 Python,但我确实成功下载/打开了 Portable Python.我在 Windows 7 64 位机器上.我如何才能使用以前的外部库,例如 Numpy 或 Gmpy?

解决方案

easy_install 正在尝试从源代码安装.gmpy 和 gmpy2 是 C 扩展,需要存在兼容的 C 编译器和其他库(GMP;以及 MPFR 和 MPC for gmpy2).在 Windows 上,从源代码安装通常很困难.安装程序包含扩展的预编译版本.

一种选择是从安装程序中提取已编译的二进制文件.7-Zip 能够打开安装程序文件,您可以解压缩二进制文件.在标准 Python 安装中,提取的二进制文件只需要放在 site-packages 目录中.如有必要,您可以在另一个系统上进行提取并复制文件.

您还可以使用 zipfile 模块来提取编译后的扩展名.这是一个例子.您需要修改确切的文件位置以反映您的系统.

<预><代码>>>>导入压缩文件>>>f=zipfile.ZipFile('gmpy2-2.0.0.win-amd64-py3.3.exe','r')>>>f.namelist()['PLATLIB/gmpy2-2.0.0-py3.3.egg-info', 'PLATLIB/gmpy2.pyd']>>>f.extract('PLATLIB/gmpy2.pyd')'C:\Python33\PLATLIB\gmpy2.pyd'

I can't install Python on my machine due to administrator privileges, but I did download/open Portable Python successfully. I am on a Windows 7 64-bit machine. How would I be able to use the external libraries from before, such as Numpy or Gmpy?

解决方案

easy_install is trying to install from source. gmpy and gmpy2 are C extensions and require the presence of a compatible C compiler and other libraries (GMP; and MPFR and MPC for gmpy2). Installing from source is frequently difficult on Windows. The installers include a precompiled version of the extension.

One option is to extract the compiled binary from the installer. 7-Zip is able to open the installer file and you can extract the binary. In a standard Python installation, the extracted binary just needs to be placed in the site-packages directory. If necessary, you can do the extraction on another system and copy the file.

You can also use the zipfile module to extract the compiled extension. Here is an example. You will need to modify the exact file locations to reflect your system.

>>> import zipfile
>>> f=zipfile.ZipFile('gmpy2-2.0.0.win-amd64-py3.3.exe','r')
>>> f.namelist()
['PLATLIB/gmpy2-2.0.0-py3.3.egg-info', 'PLATLIB/gmpy2.pyd']
>>> f.extract('PLATLIB/gmpy2.pyd')
'C:\Python33\PLATLIB\gmpy2.pyd'

这篇关于如何使用便携式 Python 安装外部库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆