How to install external libraries using Portable Python?

I cannot install Python on my computer due to administrator privileges, but I successfully downloaded / opened Portable Python. I am on a Windows 7 64-bit machine. How can I use external libraries earlier, such as Numpy or Gmpy?

+4
source share
4 answers

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

One option is to extract the compiled binary from the installer. 7-Zip can open the installer file, and you can extract the binary file. In a standard Python installation, the extracted binary just needs to be placed in the package sites directory. If necessary, you can perform 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 change the exact location of the files 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' 
+4
source

Follow these steps:

  • Find an already compiled version of the desired package - Christoph Gohlke offers an excellent collection here - download it and put it in a folder (say C:. \ Temp)
  • In your Portable Python installation, find the Scripts folder (usually in the Apps folder) and open a command prompt there.
  • In the Scripts folder, enter easy_install C:\temp\numpy-MKL-1.8.0.win32-py2.7.exe (change the name of the exe file for any name of your installer).

Check if the installation succeeded:

 >>> import numpy >>> print numpy.__version__ 1.8.0 
+1
source

refer to https://groups.google.com/forum/?fromgroups#!topic/portablepython/BVQOHFNXilU

Accordingly, for most packages, you can easily install Portable Python in your root folder and then import it as usual into your python script.

0
source

For most external packages, I was able to import them as follows:

  • Extract the package source from the corresponding .whl file in PyPI to the user "include" folder on the disk / stick with Portable Python installed.
    • In my case, this is F:\py\include - no matter what you choose, make sure that the path to this folder does not contain spaces or special characters, otherwise Portable Python will not parse it correctly added to PYTHONPATH .
    • Wheels are just ZIP files; rename .whl to .zip and Windows Explorer will open it directly.
    • Usually you want to get a subfolder in .whl whose name is just the package name you are interested in: numpy , sympy , etc.
  • Add the path to this included folder to the PYTHONPATH environment variable:
    • In Windows Explorer, right-click "Computer" and select "Properties"
    • It depends a little on the version, but select something like "Advanced System Settings" (Win7) or the "Performance" or "Advanced" (WinXP) tab.
    • Click "Environment Variables"
    • In the "System Variables" section, find PYTHONPATH . If it is there, select it and click "Edit." If not, click Create.
    • If you are adding a new one, enter PYTHONPATH as "Variable Name". In either case, add the path to your include include folder to the Variable value. If other paths already exist, separate your path from any previous one with a semicolon. DO NOT enter a space between the semicolon and the new path! Portable Python apparently interprets entries with master space as relative paths, with the reference folder being the Portable Python installation folder.
    • Click OK to save the settings and clear the dialog boxes.

In some cases, when a β€œformal” installation process is required, this does not always work. I think sympy was one of the times when I had to compile it before porting to F:\py\include . In addition, I had a rough time with h5py , but it worked in the end, installing it in the "normal" version of Python 2.7 and copying the resulting h5py to F:\py\include .

0
source

All Articles