How to install external libraries with Portable Python?

后端 未结 4 1054
遥遥无期
遥遥无期 2020-12-06 21:38

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

4条回答
  •  感动是毒
    2020-12-06 21:58

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

    1. Extract the package source from the appropriate .whl file on PyPI into a custom 'include' folder on the disk/stick with Portable Python installed.
      1. In my case, this is F:\py\include -- whatever you choose, be sure the path to this folder has no spaces or special characters in it, or else Portable Python won't parse it correctly when added to PYTHONPATH.
      2. Wheels are just ZIP files; rename the .whl to .zip and Windows Explorer will open it right up.
      3. Usually you want to retrieve the subfolder within the .whl whose name is just the package name you're interested in: numpy, sympy, etc.
    2. Add the path to this include folder to the PYTHONPATH environment variable:
      1. In Windows Explorer, right-click on 'Computer' and select 'Properties'
      2. This is a bit version-dependent, but select something like 'Advanced system settings' (Win7) or the 'Performance' or 'Advanced' tab (WinXP).
      3. Click 'Environment variables'
      4. Under 'System variables', look for PYTHONPATH. If it's there, select it and click 'Edit.' If not, click 'New'.
      5. If you're adding it new, type PYTHONPATH as the 'Variable name.' Either way, Add the path to your custom include folder into 'Variable value.' If other paths are already in there, separate your path from any prior one with a semicolon. DO NOT put a space between the semicolon and your new path! Portable Python apparently interprets entries with a leading space as being relative paths, with the reference folder being the Portable Python installation folder.
      6. Click 'OK' as needed to save the settings and clear the dialogs.

    In some cases where a "formal" installation process is required, this hasn't always worked. I think sympy was one case where I had to compile it before transferring it to F:\py\include. Also, I had a particularly rough time with h5py, but eventually got it to work by installing it into a 'normal' version of Python 2.7 and copying the resultant h5py folder over to F:\py\include.

提交回复
热议问题